How to access private data in class? – tccicomputercoaching.com

Page 1

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


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.