答案 0 :(得分:8)
答案 1 :(得分:2)
将其写为:
#include <string>
#include <iostream>
using namespace std;
template<class T> class foo{
public:
string what();
};
template<class T> string foo<T>::what(){
return "foo of type T";
}
template<> class foo<char>{
public:
string what();
};
string foo<char>::what(){
return "foo of type char";
}
int main(){
foo<char> f;
cout << f.what() << endl;
}
按预期工作。
答案 2 :(得分:0)