Archived

This topic is now archived and is closed to further replies.

i go crazy !!!!!! (lnk 2005)

This topic is 5587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

That''s my problem:
Linking...
MainFrm.obj : error LNK2005: "public: __thiscall E3DVECTOR::E3DVECTOR(void)"(??0E3DVECTOR@@QAE@XZ) already defined in ChildFrm.obj
MainFrm.obj : error LNK2005: "public: __thiscall E3DVECTOR::E3DVECTOR(float,float,float)"(??0E3DVECTOR@@QAE@MMM@Z) already defined in ChildFrm.obj
 
First, I know #ifndef...#define...#endif !! As you can see I use MFC. Everything works fine, if I make a class with the classwizard. But if I want to write my own classes then the lnk2005 error appears. I have a MFC MDI app with the ChildFrm.cpp and MainFrm.cpp files. In addition I have my own files etypes.cpp and etypes.h: etypes.cpp:
  
#ifndef _ETYPES_CPP_
#define _ETYPES_CPP_

#include "../inc/etypes.h"

E3DVECTOR::E3DVECTOR()
{
}

E3DVECTOR::E3DVECTOR(float lx,float ly,float lz)
{
	x=lx;
	y=ly;
	z=lz;
}

#endif
  
etypes.h:
  
#ifndef _ETYPES_H_
#define _ETYPES_H_

struct E3DVECTOR
{
	union
	{
		struct
		{
			float x,y,z;
		};
		float v[3];
	};

	E3DVECTOR();
	E3DVECTOR(float x,float y,float z);
	~E3DVECTOR();
};

#endif
  
If I include etypes.cpp just in childfrm.cpp, it functions. But if I want to include in both (childfrm.cpp and mainfrm.cpp), the lnk2005 is once again on my screen. Please Help!!!!!!!!!!

Share this post


Link to post
Share on other sites
You shouldn''t include etypes.cpp in anything. Instead, include etypes.h in both childfrm.cpp and mainfrm.cpp, and add etypes.cpp to your project.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i could be wrong cause i am still a newbe but
you should include only the header in the the cpp files
and dont( #ifndef _ETYPES_CPP_ #define _ETYPES_CPP_#)in the cpp files . If you include it in the childfrm.h then you should not need a second time in the mainfrm.cpp.
like i said i could be wrong i am only 13 and been at this for
this summer.

Share this post


Link to post
Share on other sites
thanks for the replies.
krunk, i''ve done it like you said.
then i got this error:

etypes.cpp(81) : fatal error C1010: unexpected end of file while looking for precompiled header directive

i put include stdafx.h at the top of etypes.cpp, and it functioned. is this the correct way? i ask because i actually don''t know why i need this stdafx in etypes. i just tried out.

Share this post


Link to post
Share on other sites
If you use VisualC++ , there is a check box in the project options somewhere, where you choose "use precompiled header directive"...

If you turn this of, it should work!

Share this post


Link to post
Share on other sites