from http://andylin02.iteye.com/blog/1019847
2011.04
- #include <iostream>
- using namespace std;
-
- class A
- {
- public:
- A()
- {
- }
-
- virtual ~A()
- {
- };
-
- public:
- virtual void fun()
- {
- cout << "A::fun()" << endl;
- }
-
- virtual void fun2()
- {
- cout << "A::fun2()" << endl;
- }
-
- void test()
- {
- cout << "A::test()" << endl;
- test2();
- fun2();
- }
-
- void test2()
- {
- cout << "A::test2()" << endl;
- }
-
- };
-
- class B:public A
- {
- public:
- B()
- {
- }
-
- virtual ~B()
- {
- }
-
- public:
- virtual void fun()
- {
- cout << "B::fun()" << endl;
- test();
- }
-
- virtual void fun2()
- {
- cout << "B::fun2()" << endl;
- }
-
- void test1()
- {
- cout << "B::test1()" << endl;
- test();
- }
-
- void test2()
- {
- cout << "B::test2()" << endl;
- }
- };
-
- int main()
- {
- cout << "========== use pointer =============" << endl;
- A* pa = new B();
- pa->fun();
- delete pa;
- cout << endl << endl;
-
- cout << "========== use object =============" << endl;
- B b;
- b.test1();
-
- return 0;
- }
执行结果
========== use pointer =============
B::fun()
A::test()
A::test2()
B::fun2()
========== use object =============
B::test1()
A::test()
A::test2()
B::fun2()
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。