|
vector::operator=public member function
vector<T,Allocator>& operator= (const vector<T,Allocator>& x); Copy vector content Assigns a copy of vector x as the new content for the vector object.The elements contained in the vector object before the call are dropped, and replaced by copies of those in vector x, if any. After a call to this member function, both the vector object and vector x will have the same size and compare equal to each other. Parameters
Return value*thisExample
Both vectors of int elements are initialized to sequences of zeros of different sizes. Then, first is assigned to second, so both are now equal and with a size of 3. And then, a newly constructed empty object is assigned to first, so its size is finally 0. Output:
ComplexityLinear on sizes (destruction, copy construction).See also
|