开发者

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?


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.


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,


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜