开发者

in which case derived class must have its own constructor?

开发者 https://www.devze.com 2022-12-18 05:06 出处:网络
In C++开发者_开发百科, in what case, the derived class must have its own constructor? what about the three cases: 1) public inheritance; 2) private inheritance; 3) protected inheritance;

In C++开发者_开发百科, in what case, the derived class must have its own constructor?

what about the three cases: 1) public inheritance; 2) private inheritance; 3) protected inheritance;

Thanks a lot.


All classes that are instantiated always have to have at least one constructor. If you don't provide one, the compiler will provide one instead.

There aren't any special rules for derived classes.


Constructors are not inherited, you have to write them explicitely for the derived class. Destructors are generated automatically, as a default constructor is generated, if the base class has a default constructor.


Constructors are not inherited. Each class needs its own constructors.

0

精彩评论

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

关注公众号