#include
#include
using namespace std;
vector aVec;
void getvectorint(vector &temp);
int main()
{
aVec.push_back(1);
aVec.push_back(5);
vector<int> temp;
getvectorint(temp);
temp.push_back(6);
int aVecsize = aVec.size();
int tempsize = temp.size();
cout<<"aVecsize="<<aVecsize<<endl;
cout<<"tempsize="<<tempsize<<endl;
return 0;
}
void getvectorint(vector &temp)
{
temp = aVec;
}
运行结果:
aVecsize = 2
tempsize = 3
为什么不都是3呢,我用的是引用啊,为什么不能对原始vector进行改变,请指教!