LNK2005 error in visual c++ (already defined in .obj)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nabh4u
    New Member
    • Jan 2007
    • 62

    LNK2005 error in visual c++ (already defined in .obj)

    hi,
    i am getting a link error in my program which states that some variable which i declared in my header file is already defined in the object file.

    The error is like this:
    error LNK2005: "struct list * first" (?first@@3PAUmy list@@A) already defined in list.obj
    error LNK2005: "struct list * last" (?first@@3PAUmy list@@A) already defined in list.obj
    error LNK2005: "struct list * current" (?first@@3PAUmy list@@A) already defined in list.obj


    this is the declaration i am using in myheader file:

    Code:
    #ifndef LIST_H
    #define LIST_H
    # include<iostream>
    # include<list>
    # include<vector>
    
    struct list
    {
    	int number;
    	list *previous;
    	list *next;
    };
    
    vector <list *> listpointer; // Vector having the pointer to the elements of the list.
    
    list *first; //  is the head of the list.
    list *last; // store the last position of the list.
    list *current; // for maintiaining the current position
    
    void add_first();
    
    #endif
    what is wrong with the declaration? how can i correct it? I have to use these variables in my cpp file.
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. Perhaps if you remove the #include <list>

    Comment

    Working...