#include <stdio.h>
class Fish
{
public:
Fish(int a) {a_ = a;}
template<typename T>
int fish()
{
printf("output fish size = %d", sizeof(T) + a_);
return 0;
}
private:
int a_;
};
int main()
{
Fish f(10);
f.fish<int>(); //模板函数的使用方法,<>放在函数之后;
return 0;
class Fish
{
public:
Fish(int a) {a_ = a;}
template<typename T>
int fish()
{
printf("output fish size = %d", sizeof(T) + a_);
return 0;
}
private:
int a_;
};
int main()
{
Fish f(10);
f.fish<int>(); //模板函数的使用方法,<>放在函数之后;
return 0;
}
另外,模板函数还有如下几种用法:见晓楚的博客:http://blog.csdn.net/maray/article/details/50977533