Is copying automatically forbidden in classes derived from a class derived from Boost noncopyable?

For example:

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

Is Bar Unavailable for Copy?

+7
source share
4 answers

By default, it is not copied unless you create your own copy constructor and call it there.

See also Explicitly Default and Remote Special Member Functions Introduced in C ++ 11. Even though creating an editor constructor or private statement solves the problem, the compiler generates a diagnostic message that is far from beautiful and obvious, therefore deleted copy instances / operators are in C ++ 11 to solve this problem.

+8
source

Assuming the derived class does not have a custom copy constructor that avoids calling an uncopy copy constructor, then yes. At all levels, all derived classes of boost::noncopyable will not be copied. Since the derived class object also contains the boost::noncopyable subobject, which is non-copyable , this means that the derived class cannot be copied if the base class cannot be copied.

+2
source

Bar comes from boost::noncopyable (even if it's not direct inheritance), so yes.

+1
source

Yes, if it was copied, then all base classes should be copied, but boost :: noncopyable is not copied

+1
source

All Articles