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

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -