f1207.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //=====================================
- // f1207.cpp
- // Virtual Function Misuse
- //=====================================
- #include <iostream>
- using namespace std;
- //-------------------------------------
- class Base{
- public:
- virtual void fn(int x){ cout<<"In Base class, int x = "<<x<<"n"; }
- };//-----------------------------------
- class Sub : public Base{
- public:
- virtual void fn(double x){ cout<<"In Sub class, double x = "<<x<<"n"; }
- };//-----------------------------------
- void test(Base& b){
- b.fn(2);
- b.fn(3.5);
- }//------------------------------------
- int main(){
- test(Base());
- test(Sub());
- }//====================================