[prog] C++ strange linking behaviour
Wolfgang Petzold
petzold at villa-chaos.de
Tue Nov 9 20:13:43 EST 2004
Am 11/09/2004 12:04 AM schrieb Meredith L. Patterson:
> Wolfgang Petzold wrote:
>> That's for *template* classes only, right? If I include the
>> implementation of non-template class methods more than once I will
>> get a "multiple definition" error ...
>
> This is what #ifndef wrappers are for. If you wrap your header file in
> preprocessor directives like [...]
I was thinking of a rather constructed example (and then again, maybe
it's not that constructed at all):
foo.h: non-template foo class and its implementation
bar.cxx: some function that uses the foo class
main.cxx: main() function that uses the foo class and the function
from bar.cxx
and then compile
bar.cxx (includes foo.h) --> bar.o \
>--> main
main.cxx (includes foo.h) --> main.o /
In this case guards won't help.
Anyway, my originating question is solved: Template class
implementation code has to be available at compile time
to any code that uses the template class.
Regards
Wolfgang
More information about the Programming
mailing list