7

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?

uj2
  • 2,255
  • 2
  • 21
  • 32
  • Doesn't simply specifying following work ? because T can be any type simple or template type also ...........Code _-------- template class A { }; – Pardeep Jun 16 '10 at 10:32
  • @Pardeep: I didn't quite follow you. `A`'s T is a template template argument. It's very deifferent from `template class A{}`. – uj2 Jun 16 '10 at 10:37
  • Why would you possibly want to? I've never seen any use for that. – Puppy Jun 16 '10 at 10:40
  • 1
    @DeadMG: I don't do exactly that. This is, however, a minimal code that reproduces the error. – uj2 Jun 16 '10 at 10:50

1 Answers1

13

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).

Kirill V. Lyadvinsky
  • 97,037
  • 24
  • 136
  • 212