Search code examples
c++inheritanceboostnoncopyable

Is copying automatically prohibited in classes derived from classed derived from Boost noncopyable?


For example:

class Foo : boost::noncopyable
{
    // ...
};

class Bar : public Foo
{
    // ...
};

Is Bar non-copyable?


Solution

  • By default it is non-copyable, unless you create a custom copy-constructor and avoid calling a base copy-constructor there.

    See also Explicitly-defaulted and deleted special member functions introduced in C++11. Even though making a copy constructor/operator private solves the problem, the compiler generates a diagnostic message that is far from pretty and obvious, so deleted copy constructors/operators are there in C++11 to solve this problem.