c++中vector的=(赋值)操作是深复制
2017-07-03 21:04
197 查看
首先是原文http://www.cplusplus.com/reference/vector/vector/operator=/
Assigns new contents to the container, replacing its current contents, and modifying its size accordingly.
附上自己的测试代码
测试结果
结果就是vector中存在=操作,该操作是赋值操作,用一个vector覆盖另一个,且是深复制。
Assigns new contents to the container, replacing its current contents, and modifying its size accordingly.
附上自己的测试代码
#include<iostream> #include<vector> 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<<b.at(i)<<endl; } a.at(0) = 666; for (int i = 0; i < b.size(); i++) { cout << b.at(i) << endl; } return 1; }
测试结果
结果就是vector中存在=操作,该操作是赋值操作,用一个vector覆盖另一个,且是深复制。
相关文章推荐
- C++ - 类的赋值操作 使用 "复制-交换(copy and swap) 技术" 详解
- C++中对象的赋值与复制操作详细解析
- C++ - 类的赋值操作 使用 "复制-交换(copy and swap) 技术" 详解
- C++ 类型自动转换 构造函数 复制构造函数 赋值操作运算符函数
- C++中对象的赋值与复制操作详细解析
- C++拷贝构造函数和赋值操作
- C++在单继承、多继承、虚继承时,构造函数、复制构造函数、赋值操作符、析构函数的执行顺序和执行内容 【转】 参考度4.6星
- c++ 深拷贝,浅拷贝,赋值操作的调用情况
- 用vector、 multimap、 list容器实现好友列表的各种操作 C++
- python 中的赋值操作,与c/c++的对比
- C++文件目录的创建,复制等操作
- c++代码测试-vector赋值, 证明是深度赋值
- C++ vector操作实例
- 聊聊C++中复制构造函数和赋值操作符
- c++ vector使用下标赋值出错
- C++复制控制之赋值操作符(二)
- 【C++】类的成员初始化表与构造函数内赋值操作
- c++ vector使用下标赋值出错
- c++的vector赋值方法汇总
- 第三章:构造函数,析构函数和赋值操作(Effective C++ Second Edition 读书笔记)