类的继承(上课用)
作者:互联网
源程序:
#include <iostream>
using namespace std;
class A
{
public:
virtual void printMe()
{
cout<<"This is class A printing."<<endl;
}
} ;
class B:public A
{
public:
void printMe()
{
cout << "This is class B printing."<<endl;
}
} ;
class C:public B
{
public:
void printMe()
{
cout <<"This is class C printing."<<endl;
}
} ;
void print(A a)
{
a.printMe();
}
void main()
{
B b;
C c;
print(b);
print(c);
}
运行结果 :
标签:上课,cout,继承,void,printMe,class,print,public 来源: https://www.cnblogs.com/duanqibo/p/16124994.html