I\'m reading C++ Primer, 3rd Ed (Lippman and Lajoie) and it\'s saying that when a vector needs to be reallocated in order to make space for more elements added with push_b
Can someone give me a simple example of a class which shouldn't be moved bit-by-bit?
By the standard, doing a memcpy
on any class that isn't a POD in C++03 (or trivially copyable in C++11) would qualify. memcpy
ing non-PODs (or non-trivially copyable) invokes undefined behavior; therefore an actual copy (or in C++11, move) constructor must be used.
So std::vector
itself applies, since it is not a POD type (and in C++11, it's not trivially copyable).