C++继承机制

1. 构造函数。
The base-class object is constructed first.
1. 首先构造基类对象。
The derived-class constructor should pass base-class information to a base-class constructor via a member initializer list.
2. 继承类应该通过成员初始化列表传递基类信息给基类构造函数。
The derived-class constructor should initialize the data members that were added to the derived class.
3. 继承类构造函数应该初始化新增的继承类数据成员。

2. 析构函数。
the body of the derived-class destructor is executed first,
and then the base-class destructor is called automartically.
首先执行继承类的析构函数,接着基类的析构函数被自动调用。

Member Initializer Lists

derived::derived(type1 x, type2 y) : base (x, y)
{
    // initializer list
}

3. 联系
One,which you’ve just seen,is that a derived-class object can use base-class methods,provided that the methods are not private.
继承类可以使用基类的方法,只要这些方法不是私有的。

Two other important relationships are that a base-class pointer can point to a derived-class object without an explicit type cast and that a base-class reference can refer to a derived-class object without an explicit type cast.
基类的指针能够在没有显式地类型转换指向一个继承类。
基类的引用能够在没有显式地类型转换引用一个继承类。
继承类不能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值