读书人

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

发布时间: 2012-02-26 20:19:44 作者: rapoo

关于函数模板显示具体化
在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)呢。

读书人网 >C++

热点推荐