Re: [Dev-C++] multiple definition linker error
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <ci...@ya...> - 2002-07-26 03:15:49
|
I had the exact same problem
Putting the #ifndef, #define & #endif do not work because
they are pre-processor directives. The linker never gets
to see them. When you create a project and compile you
will see for each *.cpp file a *.o file, these *.o files
are what the linker is given. The preprocessor has weeded
out it's directives before compiling even begins.
The problem you are having occours when you define a
function in more than one file. Please make shure you
are not confusing this with the definition of a function
which is just one line while the definition is all the
code you have the function execute
The .h file are supposed to contain the prototypes and
declarations
E.G.
void my_function(int param1, param2);
extern int my_varible;
class my_class {
public:
my_class();
~my_class()
private:
int x;
};
In a .cpp file put the function definitions
void my_function(int param1, int param2)
{
return;
}
...
P.S. Do not put #include "*.cpp" in the .h file or you
defeat the purpose
P.S. I had this same problem and pondered on it for a week
before I figured it out by trial & error
=====
Signed
David Mcken
Life Sucks
Live with it
__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com
|