1#include <iostream>2 using namespacestd;3 4 structFather5 {6 /*7 virtual bool Set () = 0;8 virtual bool Get () = 0;9 */Ten One Virtual BOOL Set(intAintb) =0; A Virtual BOOL Get(intAint*B) =0; - - }; the structJack: PublicFather - { - intx; - inty; + BOOL Set(intAintb); - BOOL Get(intAint*p); + A }; at - structMack: PublicFather - { - intx; - inty; - BOOL Set(intAintb); in BOOL Get(intAint*p); - }; to + structMackson: PublicMack - { the intx; * inty; $ BOOL Set(intAintb);Panax Notoginseng BOOL Get(intAint*p); - }; the BOOLJack::Set(intAintb) + { Ax =A; they =b; + if(A = = x && b = =y) - return true; $ Else $ return false; - } - BOOLJack::Get(intAint*p) the { - if(0==a)Wuyi { thep = &x; - return true; Wu } - Else if(1==a) About { $p = &y; - return true; - } - Else A return false; + } the - BOOLMack::Set(intAintb) $ { thex =A; they =b; the if(A = = x && b = =y) the return true; - Else in return false; the } the BOOLMack::Get(intAint*p) About { the if(0==a) the { thep = &x; + return true; - } the Else if(1==a)Bayi { thep = &y; the return true; - } - Else the return false; the } the the BOOLMackson::Set(intAintb) - { thex =A; they =b; the if(A = = x && b = =y)94 return true; the Else the return false; the }98 BOOLMackson::Get(intAint*p) About { - if(0==a)101 {102p = &x;103 return true;104 } the Else if(1==a)106 {107p = &y;108 return true;109 } the Else111 return false; the }113 the intMain () the { the 117Father *P1;118 intA=0;119 BOOL(Father::* PF) (intAintb) =0; - BOOL(father::* Pb) (intAint*B) =0;121 122P1 =NewJack;123 124PF = &father::Set; thePB = &father::Get;126 127(P1->*PF) (5,6); -(P1->*PB) (1, &a);129cout << a <<Endl; the 131 the 133 return 0;134}
This is an overload of the C + + struct implementation, multiple inheritance, polymorphism, virtual base class, abstract class, class member pointer
The main purpose is to let everyone better understand the difference between C + + struct and class
C + + struct body and class