第12章121组合与继承.ppt

第12章121组合与继承资料

第12章 组合与继承 组合 继承 虚函数与多态性 纯虚函数与抽象类 多继承 面向对象设计范例 组合 组合就是把用户定义类的对象作为新类的数据成员 组合表示一种聚集关系,是一种部分和整体(is a part of)的关系 必须用初始化列表去初始化对象成员 组合实例 定义一个复数类,而复数的虚部和实部都用有理数表示 类定义 class Complex{ friend Complex operator+(Complex x, Complex y); friend istream operator(istream is, Complex obj); friend ostream operator(ostream os, const Complex obj); Rational real; //实部 Rational imag; //虚部 public: Complex(int r1 = 0, int r2 = 1, int i1= 0, int i2 = 1):

文档评论(0)

1亿VIP精品文档

相关文档