c+++中vectorの=(賦)操作は深複製です.
2524 ワード
まず原文ですhttp://www.cplusplus.com/reference/vector/vector/operator=/
Asigns new contens to the container,replecing its current contens,and modifying its size accodingly.自分のテストコードを添付します.
Asigns new contens to the container,replecing its current contens,and modifying its size accodingly.自分のテストコードを添付します.
#include
#include
using namespace std;
int main()
{
vector<int> a;
a.push_back(1);
a.push_back(2);
a.push_back(3);
vector<int> b;
b.push_back(4);
b.push_back(5);
for (int i = 0; i < a.size(); i++)
{
cout << a.at(i) << endl;
}
for (int i = 0; i < b.size(); i++)
{
cout << b.at(i) << endl;
}
b = a;
for (int i = 0; i < b.size(); i++)
{
cout<0) = 666;
for (int i = 0; i < b.size(); i++)
{
cout << b.at(i) << endl;
}
return 1;
}
試験結果は、結果として、vectorの中に存在する=動作であり、この動作は割当動作であり、一つのvectorで他の一つをカバーし、且つ深複製である.