Linker Error #2005
-
I keep getting a linker Error 2005 about functions already being defined for every class I try and make in VS.net. I program my classes by putting the class definition in one file and them the actual code for the functions in a seperate file. for example: ***myclass.h file*** class myclass { public: void myfunc(); ..... ***myclass.cpp*** #include "myclass.h" void myclass::myfunc() { ....... This will always give me a linker error that there are two definitions for the function myfunc in the object file. I can make the error become a warning if I use the linker command /FORCE:MULTIPLE but that does not seem like the best way to overcome the problem even though the program will work fine when I do that. Does anyone have some helpfull suggestions to solving this problem. (I do not want to put the meat of the function in the class definition as sometimes the functions are rather big.)
-
I keep getting a linker Error 2005 about functions already being defined for every class I try and make in VS.net. I program my classes by putting the class definition in one file and them the actual code for the functions in a seperate file. for example: ***myclass.h file*** class myclass { public: void myfunc(); ..... ***myclass.cpp*** #include "myclass.h" void myclass::myfunc() { ....... This will always give me a linker error that there are two definitions for the function myfunc in the object file. I can make the error become a warning if I use the linker command /FORCE:MULTIPLE but that does not seem like the best way to overcome the problem even though the program will work fine when I do that. Does anyone have some helpfull suggestions to solving this problem. (I do not want to put the meat of the function in the class definition as sometimes the functions are rather big.)
-
I doubt that in myclass.h, the function is declared as void myfunc(){ }; // with brackets. this is considered as a definition. Maybe.
Im not exactly sure what you are trying to say with this are. I am not useing {} with the function in the class definition and that has been the stand that worked with every borland compiler I used in the past. I just recently started using Visual Studio.NET(2002) and now the convension gives me errors. I have even gotten errors trying to compile sample cade that was included with the Visual Studio Software. I wish I had the computer in front of me with compiler on it to try things out. but i have to wait till I get home to try anything.
-
I keep getting a linker Error 2005 about functions already being defined for every class I try and make in VS.net. I program my classes by putting the class definition in one file and them the actual code for the functions in a seperate file. for example: ***myclass.h file*** class myclass { public: void myfunc(); ..... ***myclass.cpp*** #include "myclass.h" void myclass::myfunc() { ....... This will always give me a linker error that there are two definitions for the function myfunc in the object file. I can make the error become a warning if I use the linker command /FORCE:MULTIPLE but that does not seem like the best way to overcome the problem even though the program will work fine when I do that. Does anyone have some helpfull suggestions to solving this problem. (I do not want to put the meat of the function in the class definition as sometimes the functions are rather big.)
lubatomy wrote: the class definition in one file and them the actual code for the functions in a seperate file These are the same thing. Typically, the declaration of a class typically goes in the .h file, and the definition of a class goes in the .cpp file. Anyway, at the top of the .h file, do you have something like:
#if !defined(AFX_MYCLASS_H__83972473_D4D1_4923_9BD8_0FD75D2FB39C__INCLUDED_)
#define AFX_MYCLASS_H__83972473_D4D1_4923_9BD8_0FD75D2FB39C__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000class myclass
{
}
A rich person is not the one who has the most, but the one that needs the least.