ch16_4.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //**********************
- //** ch16_4.cpp **
- //**********************
- #include <iostream.h>
- class Base{
- public:
- virtual void fn(int x)
- {
- cout <<"In Base class, int x = " <<x <<endl; }
- };
- class SubClass :public Base{
- public:
- virtual void fn(float x)
- {
- cout <<"In SubClass, float x = " <<x <<endl; }
- };
- void test(Base& b)
- {
- int i =1;
- b.fn(i);
- float f =2.0;
- b.fn(f);
- }
- void main()
- {
- Base bc;
- SubClass sc;
- cout <<"Calling test(bc)n";
- test(bc);
- cout <<"Calling test(sc)n";
- test(sc);
- }