宏接口实现纯虚函数类继承
//下列代码编译过,楼主先保存- -
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 }