Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the deletion of a constructor inherited?

Using the keyword delete you can prevent the compiler from automatically adding standard implementations of certain constructors.

Is this deletion inherited to subclasses?

like image 864
iFreilicht Avatar asked Aug 02 '14 20:08

iFreilicht


People also ask

Is constructor is inherited or not?

Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.

Are constructors and destructors inherited?

Derived classes do not inherit or overload constructors or destructors from their base classes, but they do call the constructor and destructor of base classes. Destructors can be declared with the keyword virtual .

What happens to constructor in inheritance?

Constructor is automatically called when the object is created. Multiple Inheritance: Multiple Inheritance is a feature of C++ where a class can derive from several(two or more) base classes. The constructors of inherited classes are called in the same order in which they are inherited.

Are constructors inherited in C?

This is all or nothing - you cannot inherit only some constructors, if you write this, you inherit all of them. To inherit only selected ones you need to write the individual constructors manually and call the base constructor as needed from them. Historically constructors could not be inherited in the C++03 standard.


1 Answers

Apparently, but I wouldn't exactly say that the attribute is inheirited. It is due to the fact that the compiler generated derived class constructor uses the base class constructor. For example, the compiler generated default constructor of a derived class uses the default constructor of the base class. So if the base class default constructor does not exist, for whatever reason (whether it was explicitly deleted, or some other reason), the compiler cannot generate a default constructor for the derived class. But this doesn't stop you from creating your own constructor for the derived class which uses a different base class constructor than the one which was deleted.

like image 167
Benjamin Lindley Avatar answered Nov 10 '22 18:11

Benjamin Lindley