R
ruebezaehler
Hello,
I should separate the definition and declaration of template code. This
works fine for non-specialized templates. But I do not know how to do
this for specialized templates.
Example:
template<typename T>
class C_B
{
public:
T var;
public:
C_B( void );
virtual ~C_B( void );
};
template<typename T>
C_B<T>::C_B( void ) : var(0){ return;}
template<typename T>
C_B<T>::~C_B( void ) { return;}
// specialized for char*
template<>
class C_B<char*>
{
public:
static const int MAXCHARS = 50;
char* var;
public:
C_B( void );
virtual ~C_B( void );
};
// this won't compile
template<>
C_B<char*>::C_B( void )
: var( new char[MAXCHARS+1] )
{
var[0]='\0';
return;
}
I should separate the definition and declaration of template code. This
works fine for non-specialized templates. But I do not know how to do
this for specialized templates.
Example:
template<typename T>
class C_B
{
public:
T var;
public:
C_B( void );
virtual ~C_B( void );
};
template<typename T>
C_B<T>::C_B( void ) : var(0){ return;}
template<typename T>
C_B<T>::~C_B( void ) { return;}
// specialized for char*
template<>
class C_B<char*>
{
public:
static const int MAXCHARS = 50;
char* var;
public:
C_B( void );
virtual ~C_B( void );
};
// this won't compile
template<>
C_B<char*>::C_B( void )
: var( new char[MAXCHARS+1] )
{
var[0]='\0';
return;
}