I would like to ask the community about std::vector, coming from C.
std::vector<int> temp1(4,0);
temp1[0] = 10;
std::vector<int> temp2;
temp2 = temp1;
temp1[0] = 0;
for (int i=0;i<4;i++)
std::cout<<"temp1: " <<temp1[i]<<"temp2: "<<temp2[i]<< std::endl;
temp1: 0 temp2: 10
temp1: 0 temp2: 0
temp1: 0 temp2: 0
temp1: 0 temp2: 0
at temp2 = temp1, temp2 appears to be a deep-copy, is this correct? Also, what happens in this case?
std::vector<int> temp1(4,0);
std::vector<int> temp2(4,1);
for (int i=0;i<4;i++) {
// some temp2 values filled
temp1 = temp2;
}
return 0;
when temp1 is updated, what actually happens. Is a copy made and the previous temp1's destructor called?
std::vector::operator=
does a deep copy. Its one of the main reasons whystd::vector
is so generally useful.