> To instantiate a template, the compiler has to have the source available.
> You hid the definitions of the constructor and destructor from it by
> putting it in b.cpp, so while it got the class definition when you included
> the .h, it did not have the function definitions. You got the error at the
> link stage for the same reason you would with a normal function; when the
> compiler sees a function declaration without a definition, it assumes the
> function will be linked later.

The problem is not that it's not being defined (it should be linked in by ld 
if he's got his makefile set up).  You should never need to put function 
bodies in your .h files (in fact, it's usually not recommended because it's 
harder to get deps correct in your Makefile, more things need to be 
recompiled etc.)

*thinks for a bit* ... wait, no, in this specific case, you're right.  I found 
that g++ could not compile templates properly if the source was not inlined 
in the .h file ... that is, it goes into an infinite compile loop.  They may 
have fixed that by now, but I don't know.

> To fix this remove the #include from b.cpp and either move its contents
> into b.h or #include b.cpp in b.h. Obviously those are the same as far as
> the compiler is concerned. I would suggest you consult your favorite C++
> text if you need more information; you should have a starting point now.

What he really wants to do is ensure that they're linked together.  The way 
that's done is g++ -c b.cpp; g++ -o main main.cpp b.o;

It could likely be done in one line, but this way shows you the basis for the 
Makefile (which you should write for any C++ project).

Also, the (I believe) syntax error in the b.cpp file, which I pointed out in 
another message.

> -Heschi
MIKE
-- 
Beware the JabberOrk

--
[EMAIL PROTECTED] mailing list

Reply via email to