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

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

gdi+ - WxWidgets draw a bitmap with opacity -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -