Implementing friend classes in C + + in C #

Source: Internet
Author: User

Recently doing a small program, a Class A (responsible for displaying processing) requires a lot of calls to Class B (responsible for data processing) of the function, I first thought of the friend concept in C + +, because these functions in class B do not want public, it just allows class A to invoke monitoring.

Online Search, there is no good simple implementation, but I think of the way I used to write, that is not the simplest implementation?

     Public classB {intMa; intMB; voidFA (); voidFB ();  Public classA {b b;  PublicA (B bx) { This. B =BX; }            voidff () {intMa =b.ma; intMB =B.MB;                B.fa ();            B.FB (); }        }    }

It is only necessary to place the definition of Class A in the implementation of Class B, at which point Class A can access all the methods and data of Class B. And it's easy to understand that a is either a part of B or a parasitic part of B. Only b exists, A has the meaning of existence.

C # to implement friend classes in C + +

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.