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

Started by
3 comments, last by kudi 21 years, 8 months ago
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!!!!!!!!!!
The problem of Object Oriented Programming:Everybody tells you how to use his classes, but nobody how not to do it !
Advertisement
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.
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.
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.

The problem of Object Oriented Programming:Everybody tells you how to use his classes, but nobody how not to do it !
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!
-Anders-Oredsson-Norway-

This topic is closed to new replies.

Advertisement