• Advertisement

Archived

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

Microsoft Visual C++ and class redefination

This topic is 5038 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

I am compiling with microsoft Visual c++ 6.0 and trying to use classes. I went through all the hoops creating the classes throught the "new class" feature and have included both .cpp and .h in my project. When i try to compile i come up with these linking errors. Any feedback would be greatly appreciated. myAttemp.obj : error LNK2005: "public: __thiscall LoadBitmapA::LoadBitmapA(void)" (??0LoadBitmapA@@QAE@XZ) already defined in LoadBitmap.obj myAttemp.obj : error LNK2005: "public: virtual __thiscall LoadBitmapA::~LoadBitmapA(void)" (??1LoadBitmapA@@UAE@XZ) already defined in LoadBitmap.obj myAttemp.obj : error LNK2005: "public: long __thiscall LoadBitmapA::LoadFromBitmap(char *)" (?LoadFromBitmap@LoadBitmapA@@QAEJPAD@Z) already defined in LoadBitmap.obj Debug/Zelda.exe : fatal error LNK1169: one or more multiply defined symbols found //.h file class LoadBitmap { protected: unsigned long width; unsigned long height; unsigned long * imageBuffer; public: LoadBitmap(); virtual ~LoadBitmap(); LoadBitmap & operator = (LoadBitmap & inputImage); HRESULT LoadFromBitmap(LPSTR fileName); void SetColorKey(char red,char green, char blue); void SetWidth(unsigned long width); void SetHeight(unsigned long height); void SetColor(unsigned long iX,unsigned long iY,unsigned char iRed, unsigned char iGreen, unsigned char iBlue,unsigned iAlpha); void SetImageBuffer(unsigned long * image); unsigned long GetWidth(void); unsigned long GetHeight(void); unsigned long GetColor(unsigned long iX,unsigned long iY); unsigned long * GetImageBuffer(void); }; //.cpp file LoadBitmap::LoadBitmap() { width = 0; height = 0; imageBuffer = NULL; } LoadBitmap::~LoadBitmap() { width = 0; height = 0; if(NULL != imageBuffer) { delete [] imageBuffer; imageBuffer = NULL; } } /*LoadBitmap & LoadBitmap::operator = (LoadBitmap & image) { width = image.GetWidth(); height = image.GetHeight(); SetImageBuffer(image.GetImageBuffer()); return * this; }*/ HRESULT LoadBitmap::LoadFromBitmap(LPSTR filename) { this code was taken out because it was too long and it was a redefiniton linking error anyway }

Share this post


Link to post
Share on other sites
Advertisement
Try to put a file guard in your .h file...


#ifndef MY_CLASS_NAME // this at top. MY_CLASS_NAME can be whatever you like

#define MY_CLASS_NAME

data...
data...
data...

#endif // this at the very end of the file


Share this post


Link to post
Share on other sites

  • Advertisement