Re: [Dev-C++] Where to include files
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: xRxIxPx <xr...@gm...> - 2003-10-13 21:19:56
|
At 08:15 AM 10/12/2003 -0400, Matthews wrote: >Guard statements are lines like these in your header files: > >#ifndef FOOHEADER_H >#define FOOHEADER_H > >int foo; >char *foostring; >//... That should not happen! If you include this header in two different compile units (means .cpp files), your global objects will be defined in 2 object files making the linker bailing out errornously. In general, you should only have const, static and extern variable declarations in your header files, and in ONE .cpp file the definition for your extern variables. >#endif > >Then if two files include foo.h, it won't be recompiled because FOOHEADER_H >has already been defined. Only true for one compile unit. Better have: #ifndef FOOHEADER_H #define FOOHEADER_H extern int foo; extern char *foostring; //... #endif foo1.cpp #include "fooheader.h" foo2.cpp #include "fooheader1.h" int foo=631; char* foostring=0; Cheers. |