其他分享
首页 > 其他分享> > 自考新教材-p272_3

自考新教材-p272_3

作者:互联网

源程序:

#include <iostream>
using namespace std;

class Base
{
public:
virtual void display() = 0;

};
class Derived1 :public Base
{
public:
void display()
{
cout << "Derived1 called" << endl;
}
};

class Derived2 :public Base
{
public:
void display()
{
cout << "Derived2 called" << endl;
}
};

void fun(Base *p)
{
p->display();
}

int main()
{
Derived1 b1;
Derived2 b2;
Base *p = &b1;
fun(p);
p = &b2;
fun(p);
system("pause");
return 1;
}

 

运行结果:

 

标签:p272,新教材,void,display,class,Base,fun,public,自考
来源: https://www.cnblogs.com/duanqibo/p/12261934.html