爲什麼大小低於向量是0?修改參考返回的向量
#include <iostream>
#include<vector>
using namespace std;
class A
{
public:
vector<int> T;
const vector<int>& get(){
return T;
}
void print(){
cout<< " size is "<<T.size();
// cout<<" \nelements are %d "<<T[0];
}
};
int main()
{
cout << "Hello World" << endl;
A ob;
vector<int> temp = ob.get();
temp.clear();
temp.push_back(3);
temp.push_back(5);
ob.print();
return 0;
}
有沒有機會,你的意思是'矢量&get()const'而不是'const vector &get()'? –
Eekan