Chinaunix首页 | 论坛 | 博客
  • 博客访问: 322223
  • 博文数量: 49
  • 博客积分: 653
  • 博客等级: 上士
  • 技术积分: 646
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-01 22:43
文章分类

全部博文(49)

文章存档

2018年(1)

2017年(4)

2015年(1)

2014年(6)

2013年(8)

2012年(24)

2011年(5)

分类: C/C++

2011-12-01 11:11:44

  1. /*
  2.  * test1.cc
  3.  *
  4.  * Created on: 2011-12-1
  5.  * Author: simondu
  6.  */

  7. #include "head.h"

  8. class A
  9. {
  10. public:
  11.     virtual ~A()
  12.     {
  13.     }

  14.     virtual void fun()
  15.     {
  16.         printf("A::fun\n");
  17.     }
  18.     virtual void fun2()
  19.     {
  20.         printf("A::fun2\n");
  21.     }
  22.     virtual void fun3() = 0;
  23.     void test()
  24.     {
  25.         printf("A::test\n");
  26.         fun2();
  27.         test2();
  28.     }
  29.     void test2()
  30.     {
  31.         printf("A::test2\n");
  32.     }
  33. };



  34. class B : public A
  35. {
  36. public:
  37.     virtual ~B()
  38.     {
  39.     }

  40.     virtual void fun()
  41.     {
  42.         printf("B::fun\n");
  43.     }
  44.     virtual void fun2()
  45.     {
  46.         printf("B::fun2\n");
  47.     }
  48.     virtual void fun3()
  49.     {
  50.         printf("B::fun3\n");
  51.     }
  52.     void test()
  53.     {
  54.         printf("B::test\n");
  55.         fun2();
  56.         test2();
  57.     }
  58.     void test2()
  59.     {
  60.         printf("B::test2\n");
  61.     }
  62. };


  63. /*
  64.  * main.cc
  65.  *
  66.  * Created on: 2011-12-1
  67.  * Author: simondu
  68.  */

  69. #include "head.h"
  70. using namespace std;
  71. #include "test1.cc"
  72. int main(int argc, char* argv[])
  73. {
  74.     printf("Starting...... \n");
  75.     A* pa =new B();
  76.     pa->test();
  77.     pa->fun3();

  78.     printf("----------------\n");
  79.     B b;
  80.     b.test();
  81.     printf("Ending...... \n");
  82.     return 0;
  83. }
阅读(1088) | 评论(2) | 转发(1) |
0

上一篇:没有了

下一篇:类的成员函数指针(比较深入)

给主人留下些什么吧!~~

king_road2011-12-02 10:53:28

桔子T恤: "head.h"找不到啊~.....
head.h是我定义的一个头文件, 你自己定义一个就OK了~

桔子T恤2011-12-02 00:08:09

"head.h"找不到啊~