作者在 2009-06-07 17:21:50 发布以下内容
#include<iostream>
using namespace std;
class base
{public:
virtual void fn(int x){cout<<"in base class,int x="<<x<<endl;}(1)
};
{public:
virtual void fn(int x){cout<<"in base class,int x="<<x<<endl;}(1)
};
class sub:public base
{public:
virtual void fn(int x){cout<<"in sub class,int x="<<x<<endl;}(2)
virtual void fn(double x){cout<<"in sub class,double x="<<x<<endl;}(3)
};
{public:
virtual void fn(int x){cout<<"in sub class,int x="<<x<<endl;}(2)
virtual void fn(double x){cout<<"in sub class,double x="<<x<<endl;}(3)
};
void test(base & b)
{//b.fn (2);
b.fn (3.5);
}
{//b.fn (2);
b.fn (3.5);
}
void main()
{test(base());
test(sub());
}
我看书啦 还是弄不清多态和虚函数重载
你帮我分析分析吧 用上面这个程序