C + + struct body and class

Source: Internet
Author: User

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-&GT;*PF) (5,6); -(P1-&GT;*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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.