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

函数模版特化有关问题

2012-02-13 
函数模版特化问题我的代码:#includeiostreamusingnamespacestdtemplate class_Typeclassyyy{public:t

函数模版特化问题
我的代码:
#include   <iostream>
using   namespace   std;
template <class   _Type>
class   yyy
{
public:
template <class   _T>
_T   Min(_T   first,   _T   second)
{
return   first   +   second;
}
        /*template <>
        const   char*   Min(const   char*   first,   const   char*   second)
{
char   *   c   =   "you   are   so   pig ";
return   c;
}*/
template <>
const   char*   Min(const   char*   first,   const   char*   second);
};
template <class   _Type>   template <>
const   char*   yyy <_Type> ::Min(const   char*   first,   const   char*   second)
{
char   *   c   =   "you   are   so   pig ";
return   c;
}
int   main()
{
yyy <int>   y;
cout   < <   y.Min(1,2)   < <   endl;
cout   < <   y.Min <const   char   *> ( "yy ", "uu ")   < <   endl;
system( "pause ");
}
我想在类模板外定义这个函数,可是始终不通过编译!
注释的是我在类内定义这个函数,编译通过,也运行很好!!看了好半天primer,   没有关于类外定义成员模板函数的语法,   望各位大虾指点,是否有语法的问题?

[解决办法]
没原因,规定而已,因为重载可以完成同样的功能,而编译器将好做很多。VC喜欢自己做扩展。

热点排行