May 2017
Intermediate to advanced
590 pages
17h 18m
English
You must be familiar with how friendship is declared and how it works.
To demonstrate how to implement this idiom, we will consider the following classes: Client, which has some private member data and functions (the public interface is not important here) and Friend, which is supposed to access only parts of the private details, for instance, data1 and action1(), but has access to everything:
class Client { int data_1; int data_2; void action1() {} void action2() {} friend class Friend; public: // public interface }; class Friend { public: void access_client_data(Client& c) { c.action1(); c.action2(); auto d1 = c.data_1; auto d2 = c.data_1; } };
Read now
Unlock full access