By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

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

nabh4u
P: 62
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@@3PAUmylist@@A) already defined in list.obj
error LNK2005: "struct list * last" (?first@@3PAUmylist@@A) already defined in list.obj
error LNK2005: "struct list * current" (?first@@3PAUmylist@@A) already defined in list.obj


this is the declaration i am using in myheader file:

Expand|Select|Wrap|Line Numbers
  1. #ifndef LIST_H
  2. #define LIST_H
  3. # include<iostream>
  4. # include<list>
  5. # include<vector>
  6.  
  7. struct list
  8. {
  9.     int number;
  10.     list *previous;
  11.     list *next;
  12. };
  13.  
  14. vector <list *> listpointer; // Vector having the pointer to the elements of the list.
  15.  
  16. list *first; //  is the head of the list.
  17. list *last; // store the last position of the list.
  18. list *current; // for maintiaining the current position
  19.  
  20. void add_first();
  21.  
  22. #endif
what is wrong with the declaration? how can i correct it? I have to use these variables in my cpp file.
Mar 8 '07 #1
Share this Question
Share on Google+
1 Reply


100+
P: 1,646
Hi. Perhaps if you remove the #include <list>
Mar 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.