On Oct 29, 2012, at 9:59 AM, Jens Alfke wrote: On Oct 29, 2012, at 8:39 AM, Howard Moon < email@hidden> wrote: If the header is read by more than one implementation file, the compiler will generate more than one copy of the code, probably causing problems with the linker.
There is no such problem. Try it and see. If you're getting multiply-defined symbols, then you've forgotten include guards (or #pragma once).
Huh? Of course this is a problem. I think you must have misread the description (it’s a _linker_ issue, not a compile-time issue.)
This has nothing to do with #include guards. If you have a global symbol defined (not just declared) in a header, then its definition will appear in the object code of every source file that includes that header. If there’s more than one such source file, the linker will complain that the symbol is multiply defined.
—Jens
Ah, you're talking about GLOBAL symbols. Ok, then you are correct, that will generate a linker error. I work almost exclusively with C++ classes, and was thinking of member functions. I had not considered global functions. And yes, I knew include guards were related to compile-time errors, not link-time errors, but I thought that maybe *you* had gotten mixed up as to the type of error you were expecting. My apologies.
-Howard
|