模版 无法显式专用化
- C/C++ code
#include <string>template<typename T>class tmp{public : T max(const T&,const T&);};template<typename T>T tmp<T>::max(const T&a,const T& b){ cout << "普通版本"<<endl; return a;}template<>class tmp<std::string>{public: std::string max(const std::string&,const std::string&);};template<>std::string tmp<std::string>::max(const std::string& a,const std::string& b){ cout << "特化版本"<<endl; return a;}error C2910: “tmp<std::string>::max”: 无法显式专用化
特化模版的max函数有什么错误吗?
[解决办法]
去看看c++ template吧。里面对于特化的类的成员函数的定义方式有说明的。
对于特化的类的成员函数必须像普通的成员函数那样定义。每一个T出现的地方都必须用特化的类型代替。