这是我正在尝试做的最简单的情况:
template <template <typename...> class Wrapper>
struct WrapperTraits { };
template <typename... Whatever>
struct Foo {
private:
// I want Foo here to refer to the template, and not the current
// concrete type (which is injected into the namespace by default)
using Traits = WrapperTraits<Foo>;
};
int main()
{
return 0;
}
这是 clang 3.6 上的错误(它在 gcc 4.8 和 5.2 上编译得很好):
error: template argument for template template parameter must be a class template or type alias template
using Traits = WrapperTraits<Foo>;
^
1 error generated.
Compilation failed
这是有关 godbolt 的示例:https://goo.gl/cSx6QR
感谢您的帮助!
最佳答案
没关系,想通了。需要将其范围限定为它所在的命名空间:
template <template <typename...> class Wrapper>
struct WrapperTraits { };
template <typename... Whatever>
struct Foo {
private:
using Traits = WrapperTraits<::Foo>; // explicit namespace
};
int main()
{
return 0;
}
关于c++ - 模板参数请引用自己的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34075100/