Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Prototype

Template class h/cpp

This topic is 5797 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
you must have entire template definitions in the headers (or, generally, defined before you use them).

Share this post


Link to post
Share on other sites
tnx
But does it also count for the member functions'' implementation? Just to get it straight.
Normally defs->h code->cpp? What happens here?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
this is only for templates though.

common practice for non-template classes/functions is to put the definition (ie implementation) in a cpp file.

Share this post


Link to post
Share on other sites
You can also keep the implementation in the cpp file and at the end of the header file you include the cpp file.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!