Suppose we have two template class and two specialized class
template< typename C >
class B {
public: void inc( C & x ) { ++x; }
};
template< template< typename > typename A , typename C >
class One {
C a{};
void inc( void ) { A< C >::inc( a ); }
};
// version one
template< template< typename > typename , typename C >
class One< B< C > , C > {
void inc2( void ) { inc(); inc(); }
};
// version two
template< typename C >
class One< B , C > {
void inc2( void ) { inc(); inc(); }
};
int main(){
One< B<int>, int> _one;
One< B, int> _two;
}
If i compile commenting version two i obtain:
error: template argument for template template parameter must be a class template or type alias template
class One< B< C > , C > {
i.e One doesn’t know that B< C > is a template.
Otherwise, if i compile commenting version one i obtain:
error: use of undeclared identifier 'inc'; did you mean 'inc2'?
void inc2( void ) { inc(); inc(); }
^~~
inc2
i.e One< B, C > isn’t a specialized version of One< B< C >, C >
Why this behaviour happens?
New contributor
Daniele Caliandro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.