Home > Enterprise >  Why base class copy and move constructors should not be inherited?
Why base class copy and move constructors should not be inherited?

Time:10-08

CWG2356:

Base class copy and move constructors brought into a derived class via a using-declaration should not be considered by overload resolution when constructing a derived class object.

But other constructors that are inherited from the base class only initializes the base class subobject, too.

So, why base class copy and move constructors should not be inherited?

CodePudding user response:

Keep in mind, the default implementations of the copy/move constructors of the derived class already call the base class copy/move constructors. If the base class copy and move constructors were eligible for overload resolution, you would make the following legal, which in general is not desirable:

Base b;
Derived d = b;
  • Related