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

template在member function中怎么使用?Example2为何出错

2012-02-19 
template在member function中如何使用?Example2为何出错?//Example1template classTvoidGetTheType(){co

template在member function中如何使用?Example2为何出错?
//Example   1
template <class   T>
void   GetTheType()   {   cout   < <   sizeof(T)   < <   endl;   }

//Example   2
class   CT1
{
public:
template <class   T>
void   GetTheType()   {   cout   < <   sizeof(T)   < <   endl;}
};

int   main(int   argc,   char*   argv[])  
{
        CT1   kknd;
GetTheType <int> ();
kknd.GetTheType <int> ();
return   0;
}



[解决办法]
没什么错啊。。。
[解决办法]
如果是VC 6,
请先更换编译器后重新编译 ······

VC6 对C++某些特性不支持。
[解决办法]
恩. 类的成员模板相对来说,好象是新特性, 那时候vc6已经出了段时间了.因此不能完全支持最新的C++. 建立LZ在新的编译器上尝试他们.
[解决办法]
成员偏特化对VC6来说可能太高端了……

如果错误出现在

kknd.GetTheType <int> ();

这一行,那就换个编译器吧。

热点排行