简体   繁体   English

为什么我不能使用模板化类来专门化类模板?

[英]Why can't I specialize class template with a templated class?

Why is the below partial specialization not allowed? 为什么不允许以下部分专业化? The class is specialized with a templated class: 该类专用于模板化类:

template <class T>
class ClassT{};

template<class F>
class ClassF{};

//error here
template<>
template <class T>
class ClassF <ClassT<T> >{};

int main(int argc, char* argv[])
{
    ClassF<ClassT<int> > ftx; //no error
}

The error: 错误:

tester.cpp(8): error C2910: 'ClassF<ClassT<T>>' : cannot be explicitly specialized

The original problem I was having is that I forgot to include the header of the class I was trying to specialize! 我最初遇到的问题是我忘了包含我尝试专门研究的类的标题! Of course that would never work but the error message was not clear enough: I did not get undefined identifier or something similar which would have been more useful. 当然,这永远不会起作用,但是错误消息还不够清楚:我没有得到undefined identifier或类似的东西,这会更有用。 So that's why I was fiddling with syntax, trying template<> trick etc. 这就是为什么我不喜欢语法,尝试template<>技巧等的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM