Proper syntax for a templated constructor using template template parameters
I'm trying to extend my (limited) understanding of class templates to class templates with template template parameters.
This declaration and constructor works fine (well, it compiles):
template < char PROTO >
class Test
{
public:
Test( void );
~Test( void );
void doIt( unsigned char* lhs, unsigned char* rhs );
};
template< char PROTO >
Test<PROTO>::Test( void )
{
}
But, when I try to do something similar using templated template parameters, I get these errors (line that sourced the errors is below):
error: missing ‘>’ to terminate the template argument list error: template argument 1 is invalid error: missing ‘>’ to terminate the template argument list error: template argument 1 is invalid error: expected initializer before ‘>’ token
t开发者_高级运维emplate <char v> struct Char2Type {
enum { value = v };
};
template < template<char v> class Char2Type >
class Test2
{
public:
Test2( void );
~Test2( void );
void doIt( unsigned char* lhs, unsigned char* rhs );
};
template< template<char v> class Char2Type >
Test2< Char2Type<char v> >::Test2( void ) //ERROR ON THIS LINE
{
}
I'm using gnu g++. What's wrong with the line above??
Try this
template< template<char v> class Char2Type >
Test2<Char2Type>::Test2( void )
{
}
A template-argument for a template template-parameter shall be the name of a class template.
Char2Type
is the template-name whereas Char2Type<char>
is the template-id. You are not allowed to use template-id
in place of template-name
in your example.
Difference between template-name and template-id.
精彩评论