Re: [Dev-C++] what is a resource? how do I create my own headers?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Luc M. <lu...@ho...> - 2001-01-05 02:39:20
|
----- Original Message ----- From: "Ioannis Vranos" <no...@ya...> To: <dev...@li...> Sent: Thursday, January 04, 2001 6:52 PM Subject: RE: [Dev-C++] what is a resource? how do I create my own headers? > > The #ifdef/#endif only works for the current compile. So, if you include > > a header file that contains a definition in more than one translation unit > > (.cpp file), you will get multiple definitions of the function, which is > > gonna > > be flagged as an error by the linker. > > I agree with you, but why create many definitions in many cpp files? Except > of that, you can use #ifndef at definitions too (it is called "conditional > compilation"). > Anyway, if i remember well we were talking about definitions included in > the header file, not external source code files (where as i said we can use > conditional compilation too). I don't see where I might have hinted at having "many definition in many .cpp files". In C/C++ (I don't know for other languages), you can't have more than one definition for a symbol, be it a variable, a function or a class. This is called, IIRC, the "One Definition Rule". If you start putting definitions in header files, as projects grow bigger, those header files risk being included in more than one .cpp file, leading to multiple definitions of the functions in the header files. Now, I've seen tricks posted here to work around this, but why use tricks when all you have to do is _declare_ your functions (or classes) in a header file, and _define_ said functions (or classes) in only one .cpp file. Then, wherever you need that function, all you need to do is #include your header file. Let the linker do its job :-) Regards, Luc Morin |