7

For example:

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

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

Is Bar non-copyable?

Emile Cormier
  • 28,391
  • 15
  • 94
  • 122

4 Answers4

8

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.

NHDaly
  • 7,390
  • 4
  • 40
  • 45
2

Assuming the derived class doesn't have custom copy-constructor which avoids calling the noncopyable copy-constructor, then yes. At all level, all derived classes of boost::noncopyable would be non-copyable. As object of derived class also contains the subobject of boost::noncopyable which is non-copyable, that means no derived class can be copyable without base-class being copyable,

Nawaz
  • 353,942
  • 115
  • 666
  • 851
1

Bar derives from boost::noncopyable (even though it's not a direct inheritance), so yes.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
1

Yes, if it were copyable then all base classes must be copyable, but boost::noncopyable is non-copyable

ks1322
  • 33,961
  • 14
  • 109
  • 164