|
-
May 4th, 1999, 10:51 PM
#1
About Error LNK2005
I define some globle variable in my class,and In other class
I define this class's instance,When linking,
there show "error LNK2005,...already defined in *.obj",
why?
For example:
//myclass.h
DWORD dwMyData;
class CMyClass
{
public:
CMyClass(){}
};
//myotherclass.h
#include "myclass.h"
welcome to call me icq 35358130
-
May 5th, 1999, 12:27 AM
#2
Re: About Error LNK2005
hi,
If a global var is declared in the header file and if the header file is included in multiple CPP files, this error occurs. The global variable will be initialized in every CPP file. so during linking you'll get this error. To avoid this, you can put all the global variables in a seprate header file and include that header file wherever required.
For example,
#ifndef _GLOBAL_H_
#define _GLOBAL_H_
DWORD dwMyData;
#endif // _GLOBAL_H_
hope this solves your problem.
Regards,
Kalyan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|