Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template class that refers to itself as a template template parameter?

This code:

template <template <typename> class T>
class A
{
};

template <typename T>
class B
{
    A<B> x;
};

doesn't compile, I suppose since A<B> is interpreted as A<B<T> > within B's scope.

So, how do you pass B as a template template parameter within it's scope?

like image 563
uj2 Avatar asked Jun 16 '10 10:06

uj2


1 Answers

Try this:

template <typename T>
class B
{
    A< ::B > x; // fully qualified name for B
};

According to C++ Standard 14.6.1/2 you should use the normal name of the template (i.e., the name from the enclosing scope, not the injected-class-name).

like image 170
Kirill V. Lyadvinsky Avatar answered Sep 20 '22 08:09

Kirill V. Lyadvinsky