TCCI-Tririd Computer Coaching Institute is focused on providing Quality education with practical sessions.Satisfaction of our student is our priority. We pride ourselves for providing proficient IT solutions. We have a highly qualificated and expereinced faculties, who, not only handle teaching, but also aspire to provide the best possible solution through their technical expertise.
Showing posts with label Programming Langauge. Show all posts
Showing posts with label Programming Langauge. Show all posts
Saturday, May 25, 2019
Tuesday, May 21, 2019
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,
Output
To learn programming
concepts in Best way, join TCCI in Satellite and
Bopal-Ahmedabad.
Call us @ 9825618292
Visit us @ http://tccicomputercoaching.com/
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
int addFive(Distance d)
{
//accessing private data from non-member function
d.meter += 5;
return d.meter;
}
int main()
{
Distance D;
cout<<"Distance: "<< addFive(D);
return 0;
}
Distance: 5
Call us @ 9825618292
Visit us @ http://tccicomputercoaching.com/
Subscribe to:
Posts (Atom)
