Category Archives: C++

std::vector and Noncopyable

When I inherited my class from boost::noncopyable, I immediately got a compilation error saying std::vector cannot access the copy constructor of my class. But I was using emplace_back, how could that happen? Because explicitly defining or deleting copy constructor will prevent the compiler from implicitly defining move constructor and move assignment operator. Thus, when the vector tries to change the location of the object when it has to grow, it will find it impossible.

References