正在加载图片...
2. #include <iostream. h class base dpublic: Base(int x, int y) a=x; b=y void Showo cout<<" Base <b<<end; private: int a, b class Derived public Base dpublic: Derived (int x, int y, int z): Base(x, y), c(z) void Showo cout<< Derived: <<c<<end; j private: int c;; void maino i Base b(50, 50), pb; Derived d( 10, 20, 30); pb=&b pb->ShowO 运行结果为 d Show O; Base:50,50 Derived: 30 C++程序设计课件设计制作:徐龙琴C++程序设计课件 设计制作:徐龙琴 5 2. #include <iostream.h> class Base {public: Base(int x,int y) { a=x; b=y; } void Show() { cout<<"Base: "<<a<<","<<b<<endl; } private: int a,b;}; class Derived : public Base {public: Derived(int x,int y,int z) : Base(x,y),c(z) { } void Show() { cout<<"Derived: "<<c<<endl; } private: int c;}; void main() { Base b(50,50),*pb; Derived d(10,20,30); pb=&b; pb->Show(); d.Show(); } 运行结果为: Base:50,50 Derived:30
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有