This compiles:
int* p1;
const int* p2;
p2 = p1;
This does not:
vector v1;
vector v2;
v2 = v1;
It would be perfectly possible to write your own version of vector
where this was possible. It would be identical to the standard type, but with a templated version of operator=
, something like this:
template
vector2 &operator=(const vector2 &other)
{
assign(other.begin(), other.end());
return *this;
}
Where T is the element type of the whole class, whereas A is any type assignable to T.
It's not clear to me why std::vector
doesn't have this.