Here's gcc's page on how they do template instantiation.
http://gcc.gnu.org/onlinedocs/gcc-3.2.2/gcc/Template-Instantiation.html
I personally would love to have definitions in something other than a .h, as it seems wrong. Stroustrup in "The Design and Evolution of C++" concurs on...
There are some caveats though. You have to wrap all types that go into/out of your secret code. If you have a need to construct values of user based types (template arguments), you'll need to add hooks for delegated instantiation. You'll likely run into the fact that gcc loves to give errors...
/* this is the way that hides your code. the namespace
* SecretLogger can be defined in any linked file. Wrapped
* also acts like a constraint on the Logger template as
* only the functions declared there are available in your
* hidden code
*/
#include <iostream>
#include <string>
class...
/*
* This is the normal way of doing things, all in a header.
* Even if YOU can get around it, your clients can't if they
* use gcc
*/
#include <iostream>
#include <string>
template< class SomeT > class Logger
{
public:
bool log(const SomeT& a_problem);
};
template< class SomeT...
/* here's the main code that I used unchanged for both of the following code structures */
#include <iostream>
#include <string>
/* I changed this line to a different header but no other changes to this file */
#include "sample3.hh"
class myImpl : public std::string
{
public...
There are ways to work around this.
However, consider the following questions
1) If you don't share a definition of the template no one else is going to be able compile custom versions of the template (it doesn't have to be this way, but it is as templates never really got past the glorified...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.