假设我有以下课程:
template<typename T>
class Dummy {
public:
Dummy() {}
template<bool U>
bool something(); // line 10
};
我想专门研究方法Dummy<T>::something
。我试过了:
template<typename T>
bool Dummy<T>::something<true>() { // line 14
return true;
}
template<typename T>
bool Dummy<T>::something<false>() { // line 19
return false;
}
但我收到这些错误:
test.h:14:32: error: template-id ‘something<true>’ in declaration of primary template
bool Dummy<T>::something<true>() {
^
test.h:14:6: error: prototype for ‘bool Dummy<T>::something()’ does not match any in class ‘Dummy<T>’
bool Dummy<T>::something<true>() {
^
test.h:10:8: error: candidate is: template<class T> template<bool b> bool Dummy<T>::something()
bool something();
^
test.h:19:33: error: template-id ‘something<false>’ in declaration of primary template
bool Dummy<T>::something<false>() {
^
test.h:19:6: error: prototype for ‘bool Dummy<T>::something()’ does not match any in class ‘Dummy<T>’
bool Dummy<T>::something<false>() {
^
test.h:10:8: error: candidate is: template<class T> template<bool b> bool Dummy<T>::something()
bool something();
这是因为它是部分特化的一种形式(我知道在C ++ 11中不允许)或其他原因吗?请注意,我绝不打算使用上述代码。它只是为了展示我原始代码中存在的类似内容。