参考博客:http://blog.csdn.net/hexi_2000/article/details/4392107
- //重载,覆盖,隐藏举例
- #include <iostream>
- using namespace std;
- class A
- {
- public:
- int n;
- void fun()
- {
- cout<<"A::fun()"<<endl;
- }
- virtual void fun(int a)
- {
- cout<<"A::fun(int)"<<endl;
- }
- void fun(double f)
- {
- cout<<"A::fun(double)"<<endl;
- }
- };
- class B:public A
- {
- public:
- int n;
- void fun(int a)
- {
- cout<<"B::fun(int)"<<endl;
- }
- void fun(double f)
- {
- cout<<"B::fun(double)"<<endl;
- }
- };
- int main(int argc, char *argv[])
- {
- A a;
- B b;
- A *p;
- p=&b;
- p->fun();
- p->fun(20);
- p->fun(19.9);
- b.fun(19.9);
- b.n=5;
- cout<<b.A::n<<endl;
- return 0;
- }
来源: http://www.bubuko.com/infodetail-2303452.html