std vector C++ -- deep or shallow copy(标准向量 C++——深拷贝或浅拷贝)
问题描述
我想知道是否复制向量我正在复制向量及其值(而这不适用于数组,并且深度复制需要循环或 memcpy).
I wonder whether copying a vector I am copying the vector with its values (whereas this is not working with array, and deep copy need a loop or memcpy).
你能提示解释吗?
问候
推荐答案
每次复制向量时,您都在进行深层复制.但是,如果您的向量是指针向量,则您将获得指针的副本,而不是指向的值
You are making a deep copy any time you copy a vector. But if your vector is a vector of pointers you are getting the copy of pointers, not the values are pointed to
例如:
这篇关于标准向量 C++——深拷贝或浅拷贝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!