In the std::vector class, you may need to redistribute the main dynamic array when you repeatedly call push_back() to add new elements. A common strategy is to std::vector increase the size of the base buffer by a factor, possibly a factor of 2 .
When this redistribution really happens, the copy constructor (or the move constructor, if you define it and use c++0x ) is called to copy the vector elements from the old buffer to the new one.
Your copy constructor does not actually copy correctly, you must assign the num_IN parameter:
a_class(a_class const& src): num_IN(src.num_IN) {}
Typically, with STL containers, stored data types must obey a three- rule rule in that the constructor, copy constructor, assignment operator, and destructor all work together.
With move semantics in c++0x I assume that this should be extended to the βrule of fiveβ in that you should also consider correctly defined move constructors and move assignment operators.
source share