#include <iostream.h>
class A
{
public:
virtual void print()
{
cout<<"A::print()"<<endl;
}
};
class B:public A
{
public:
virtual void print()
{
cout<<"B::print()"<<endl;
}
};
class C:public B
{
public:
virtual void print()
{
cout<<"C::print()"<<endl;
}
};
void print(A a)
{
a.print();
}
void print(A *pa)
{
pa->print();
}
void printS(A &a)
{
a.print();
}
void main()
{
A a,*pa,*pb,*pc;
B b;
C c;
pa=&a;
pb=&b;
pc=&c;
a.print();
b.print();
c.print();
pa->print();
pb->print();
pc->print();
print(a);
print(b);
print(c);
print(pa);
print(pb);
print(pc);
printS(a);
printS(b);
printS(c);
printS(*pa);
printS(*pb);
printS(*pc);
}
虚函数多态性小练习
Fight fight fight ! 你有你的奇迹 !
Fight fight fight ! Just to be yourself !
推荐阅读
- 【已解决】Endnote 20 登陆账户不能同步,提示:EndNote registration could not be completed at this time. Please contact technical support.
- 【已解决】win10便笺(sticky note)一直加载无法打开
- Matlab提示——未定义与 'double' 类型的输入参数相对应的函数 'resample'
- matlab学习笔记(4)
- 上(下)三角矩阵
- JqGrid自定义获取编辑中单元格的值
- SQL SERVER 索引
- Java学习笔记-2020学习目录
- Java 使用UDP、TCP进行网络通信
- nodejs cheerio模块提取html页面内容