以为模版类对象传递引用有区别

来源:互联网 发布:武迪 知乎 编辑:程序博客网 时间:2024/06/06 02:38
么有区别,看例子,话说为啥我会觉得别扭

#include<iostream>
using namespace std;
#include<stack>

int shishi(stack<int>& a)
{
 cout << "size :" << a.size() << endl;
 return 0;
}
template <typename T>
int anothershi(stack<T>& a)
{
 cout << "size :" << a.size() << endl;
 return 0;
}

int main()
{
 stack<int> b;
 b.push(4);
 b.push(4);
 b.push(4);
 b.push(4);
 shishi(b);
 anothershi(b);
 return 0;
}


输出: 
size :4
size :4 
0 0
原创粉丝点击