Container requirements have changed from C++03 to C++11. While C++03 had blanket requirements (e.g. copy constructibility and assignability for vector), C++11 defines fine-g
Even though we already have very good answers on this, I decided to contribute with a more practical answer to show what can and what cannot be done.
So this doesn't work:
vector vec;
Just read the other answers to understand why. And, as you may have guessed, this won't work either:
vector> vec;
T
is no longer const
, but vector
is holding shared_ptr
s, not T
s.
On the other hand, this does work:
vector vec;
vector vec; // the same as above
But in this case, const is the object being pointed to, not the pointer itself (which is what the vector stores). This would be equivalent to:
vector> vec;
Which is fine.
But if we put const
at the end of the expression, it now turns the pointer into a const
, so the following won't compile:
vector vec;
A bit confusing, I agree, but you get used to it.