How to access private data in class? – tccicomputercoaching.com The Friend function and friend class are the techniques used to access the private members of a class by using friend keyword. A friend function is required when a function needs to access two or more independent classes, internal members.
For example, #include <iostream.h> class Distance { private: int meter; public: Distance(): meter(0) { } //friend function friend int addFive(Distance); }; // friend function definition