首页 > 其他 > 详细

宏接口实现纯虚函数类继承

时间:2017-07-02 13:35:15      阅读:332      评论:0      收藏:0      [点我收藏+]

//下列代码编译过,楼主先保存- -

 

 1 #include <iostream>
 2 #include <string>
 3 
 4 
 5 #define INTERFACE_ANIMAL(terminal)                           6 public:                                                      7     virtual std::string GetName() const ##terminal           8     virtual void GetPosition() const ##terminal              9     virtual void GetVelocity() const ##terminal
10 
11 #define BASE_ANIMAL     INTERFACE_ANIMAL(=0;)
12 #define DERIVED_ANIMAL  INTERFACE_ANIMAL(;)
13 
14 
15 // Animal.h
16 class Animal
17 {
18 BASE_ANIMAL;
19 
20 };
21 
22 
23 // Monkey.h
24 class Monkey : public Animal
25 {
26 DERIVED_ANIMAL;
27 };
28 
29 
30 // Lion.h
31 class Lion : public Animal
32 {
33 DERIVED_ANIMAL;
34 };
35 
36 
37 // Tiger.h
38 class Tiger : public Animal
39 {
40 DERIVED_ANIMAL;
41 };
42 
43 int main()
44 {
45     return 0;
46 }

 

宏接口实现纯虚函数类继承

原文:http://www.cnblogs.com/xuaidongstdudyrecording/p/7105761.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!