最近学习到了template
发现她每次宣告都需要再function前面加上template
可是我觉得它的功用跟typedef其实是一样的
但typedef定义了以后可以用在function里也可以用在main里的变量
template却只能用在function里
ex:
typedef int elemType;
template<calss T>
calss node{
};
int main()
{
node<int> head;
int data;//此时我要改template的型别这边也要改一次
return 0;
}
但如果用typedef我只需要把变量都改成elemType,接着改elemType的型别就好
结论就是:不太知道template的好处在哪里...
有人可以帮我分析一下template的好处吗???