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

关于函数模板显示具体化解决方法

2012-02-26 
关于函数模板显示具体化在vc2005下编译报错:(原型)template classTTmax(Ta)templatestringmax strin

关于函数模板显示具体化
在vc2005下编译报错:(原型)
template <class   T>
T   max(T   a);

template   <>   string   max <string> (string   a[]);//   explicit   specialization;   'std::string   max <std::string> (std::string   []) '   is   not   a   specialization   of   a   function   template
把 <string> 去掉后
template <class   T>
T   max(T   a);

template   <>   string   max(string   a[]);
//error   C2782:   'T   max(T) '   :   template   parameter   'T '   is   ambiguous
                d:\my   documents\visual   studio   2005\projects\super\super\super.cpp(12)   :   see   declaration   of   'max '
                could   be   'std::string '
                or   'std::string   [] '
…………


[解决办法]
template <> string max(string a[]);
自己认真看啊,返回类型T是string, 参数类型T是string [],不一样啊,怎么可以匹配T max(T a)呢。

热点排行