Our Craft

Making it better

Defining your C++ template in a .cpp file

Posted by danielmeyer on October 21, 2009

Normally all your C++ template classes are implemented in their header files, and when we  tried to move the definition of a template class out to a .cpp file, the compiler complained.  I thought I remembered reading in Stroustrup’s The C++ Programming Language of  a keyword  that could help with this very issue, last time I was doing C++ programming.  A little digging turned up the name of the keyword: export (TC++PL §9.2.3).  However, it’s currently not a good option (also see the beginning of the discussion).

So, back into the header it goes.  :)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>