Template class h/cpp
I have a problem with my templated list class when I split it up in h/cpp. Classes that use it come up with unresolved externals.
Now I thought I read somewhere template class methods must remain in the .h file.
Is that correct? I''m using VC6.
you must have entire template definitions in the headers (or, generally, defined before you use them).
tnx
But does it also count for the member functions'' implementation? Just to get it straight.
Normally defs->h code->cpp? What happens here?
But does it also count for the member functions'' implementation? Just to get it straight.
Normally defs->h code->cpp? What happens here?
declarations ''declare'' that something exists.
definitions ''define'' how it''s done.
as niyaw says, the definitions go in the headers. at the same time they act as declarations.
definitions ''define'' how it''s done.
as niyaw says, the definitions go in the headers. at the same time they act as declarations.
quote:Original post by Prototype
tnx
But does it also count for the member functions'' implementation? Just to get it straight.
Normally defs->h code->cpp? What happens here?
Templates, just like inline functions go in headers, since their implementation must be visible from the instanciation point.
That''s all.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
Ah thanks. One obscurity less.
I''ve switched to VC recently after years of Delphi and including gives me a headache in C++. The rest of the transition went quite smooth though.
I''ve switched to VC recently after years of Delphi and including gives me a headache in C++. The rest of the transition went quite smooth though.
this is only for templates though.
common practice for non-template classes/functions is to put the definition (ie implementation) in a cpp file.
common practice for non-template classes/functions is to put the definition (ie implementation) in a cpp file.
You can also keep the implementation in the cpp file and at the end of the header file you include the cpp file.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement