当我研究模板专业化时,我使用了一个非常简单的示例,但仍然出现错误。模板专业化:不匹配任何模板声明
#include <iostream>
template <class T>
class chrrr{
public:
T chgchr(T c);
};
template < class T>
T chrrr<T>::chgchr(T c){
return c+1;
}
template <>
class chrrr<char>{
public:
char chgchr(char c);
};
template <>
char chrrr<char>::chgchr(char c){
return c+2;
}
using namespace std;
int main(){
char a='a';
int i=1;
chrrr<int> it;
chrrr<char> ch;
cout<<ch.chgchr(a)<<endl;
cout<<it.chgchr(i)<<endl;
return 0;
}
错误说:
line 20: error: template-id ‘chgchr<>’ for ‘char chrrr<char>::chgchr(char)’ does not match any template declaration
我不知道为什么它剂量不匹配?如果我在类定义主体中定义chgchr而不是在外侧,它会很好地工作。
感谢德鲁编辑! – Kuan 2013-03-27 16:19:19