我有一个模板类MYVEC
,它作为第二个模板参数传递给另一个模板类FOO
template<class T>
class MYVEC{ };
template<class T,class U>
class FOO { };
main()
{
FOO<int, MYVEC<int>> obj;
}
如果我可以通过上述方式实例化 FOO
,那么为什么我需要模板模板参数语法?
例如我什么时候需要以下内容:
template<class T>
class MYVEC{ };
template<class T, template<typename> class C> //or template<class T, template<typename> class C=MYVEC>
class FOO { };
此外,我的编译器在尝试将其实例化为时不会抛出任何错误:
FOO<int, MYVEC> obj; //I wonder what is the second template param type here
但这是一个编译器错误,尽管我希望它能工作:
FOO<int, MYVEC<int>> obj;
最佳答案
为了切入错误的本质,它本质上是在告诉您 MYVEC<int>
不是模板类型,因为该类型已完全实现。而当您使用MYVEC
时,这是一个模板类型,因为它仍然需要一个模板参数。
关于c++ - template 模板参数场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59320876/