关闭

C++继承机制

142人阅读 评论(0) 收藏 举报
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.
基类的指针能够在没有显式地类型转换指向一个继承类。
基类的引用能够在没有显式地类型转换引用一个继承类。
继承类不能。
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:363次
    • 积分:33
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档