首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

模版 无法显式专用化,该怎么处理

2012-03-29 
模版 无法显式专用化C/C++ code#include stringtemplatetypename Tclass tmp{public :T max(const T&,

模版 无法显式专用化

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出现的地方都必须用特化的类型代替。

热点排行
Bad Request.