c++ - what is the difference between friend function and friend class? -
what difference between friend function , friend class? , should use of friend keyword?
in short, 1 class , 1 function. function, 1 function gets access private members. class, whole class , functions access private members of befriended class.
the friend keyword used grant access private data members. @ times may need helper class or complimentary class access private members of different class. functions, common example operator overload. perhaps want overload + operator. may make operator+ function declared outside class (so can called without object) , need access private class data.
check out this site detailed description of both , how use them.
Comments
Post a Comment