//第一节的内容是多重继承,由于前面在继承那一章已经粗略地了解了多种继承,所以本节及后面几节主要是说明"为什么要使用多重继承"/*#includeusing namespace std;class father{public: void smart() { cout<<"父亲很聪明"< >choice; switch(choice) { case 0: quit = true; break; case 1: pf = new father; pf->beautiful(); break; case 2: pf = new son; pf->beautiful(); pf->smart(); delete pf; break; default: cout<<"请输入从0到2之间的数字"< using namespace std;class father{public: void smart() { cout<<"父亲很聪明"< >choice; switch(choice) { case 0: quit = true; break; case 1: pf = new father; //pf->beautiful(); break; case 2: pf = new son; //pf->beautiful(); //father类已经没有beautiful()函数,所以这里不能访问 //只能用指针转换 dynamic_cast (pf)->beautiful(); //因此我们必须将基类指针强制转换为子类指针,这里要用到一个方法--dynamic_cast //dynacic_cast的作用是对不同类之间的数据类型进转换,它可一个基类的指针转换成一个派生类的指针 pf->smart(); delete pf; break; default: cout<<"请输入从0到2之间的数字"< using namespace std;class father{public: void smart() { cout<<"父亲很聪明"< >choice; switch(choice) { case 0: quit = true; break; case 1: pf = new father; break; case 2: pm = new son; pm->beautiful(); delete pm; break; default: cout<<"请输入从0到2之间的数字"< using namespace std;class Human{public: Human(){cout<<"构造Human"< >choice; switch(choice) { case 0: quit = true; break; case 1: p = new father; p->beautiful(); delete p; break; case 2: p = new son; //这里产生了两义性,因为父亲和母亲类都是从人类来的,一分是从母类,一分是从父类 p->beautiful(); p->smart(); delete p; break; case 3: p = new mother; p->beautiful(); delete p; default: cout<<"请输入从0到2之间的数字"< using namespace std;class Human{public: Human(){cout<<"构造Human"< >choice; switch(choice) { case 0: quit = true; break; case 1: p = new father; p->beautiful(); p->smart(); delete p; break; case 2: p = new son; //这里产生了两义性,因为父亲和母亲类都是从人类来的,一分是从母类,一分是从父类 p->beautiful(); p->smart(); delete p; break; case 3: p = new mother; p->beautiful(); p->smart(); delete p; default: cout<<"请输入从0到2之间的数字"< using namespace std;class Shape{public: virtual double area()=0;};//三角形class Trigon: public Shape{protected: double h, w;public: Trigon(double H, double W) { h = H; w = W; } double area() { return h * w / 2; };};//正方形class Square : public Trigon{public: Square(double H, double W):Trigon(H, W) { } double area(){return h*w;}};//圆class Circle: public Shape{protected: double radius;public: Circle(double r){radius = r;} double area(){ return radius * radius * 3.14; }};int main(){ Shape *p; int choice = 0; while(1) { bool quit = false; cout<<"(0)退出 (1)三角形 (2)正方形 (3)圆"< >choice; switch(choice) { case 0: quit = true; break; case 1: p = new Trigon(5.0,6.0); cout<<"三角形的面积是:"< area()< area()< area()< 0){ delete p; } if(quit == true){ break; } }; return 0;}*/