开发者

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

开发者 https://www.devze.com 2023-01-03 10:46 出处:网络
This code: template <template <typename> class T> class A { }; template <typename T> class B

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 temp开发者_StackOverflow中文版late template parameter within it's scope?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消