+ 10

What is the main reason of using a friend class?

Anyone please!

13th Jun 2016, 5:05 PM
Utpal Kumar
Utpal Kumar - avatar
13 Respuestas
+ 8
to access private data members with a non-member function
14th Jun 2016, 9:31 AM
Sardor
Sardor - avatar
+ 4
it's when you are lazy enough to not think with inheritance in mind
13th Jun 2016, 6:24 PM
Klodian Lula
Klodian Lula - avatar
+ 3
thanks!
14th Jun 2016, 10:04 PM
Utpal Kumar
Utpal Kumar - avatar
+ 3
To access private member functions of a particular class. We don't define private members as public because then everyone will have access to members of class thus failing the concept of data hiding. But by defining friend functions we can give the right of accessing private members only to those functions which we want to access class's private members.
20th Jul 2016, 7:46 AM
Arpna Joshi
Arpna Joshi - avatar
+ 2
To access private data members and private functions in a class from a different class. This can be useful for example when writing unit tests for a class as it enables you to write tests for private member functions. Moreover, it allows to implement more fine-grained access policies.
19th Jun 2016, 8:14 PM
Max Dörner
+ 2
So that it can access all the private data without a member function. But it's suggested not to use because u access private data . Which is against to the convention of C++
9th Jul 2016, 1:27 PM
Desik
Desik - avatar
+ 1
to access private data members of the class,and modify it. It is not a member function of the class but still it can access the private members and modify them.
19th Jun 2016, 6:12 PM
Reddy Jahnavi Tenepalli
Reddy Jahnavi Tenepalli - avatar
0
Thanks so much!
18th Jun 2016, 10:37 PM
Utpal Kumar
Utpal Kumar - avatar
0
first of all friend is not a class but a function and used to access private data members of a class with a non-member function outside the class
22nd Dec 2016, 5:00 AM
blumen
blumen - avatar
0
friend function used to access private data
22nd Dec 2016, 7:22 AM
Mohan Chandra
Mohan Chandra - avatar
0
if you want to use private access specifier outside the class then with the friend member function you access private property of class.
22nd Dec 2016, 7:49 AM
himanshu yadav
himanshu yadav - avatar
0
Para poder tener acceso a miembros privados de una clase
13th May 2021, 2:36 AM
edilberto Coello Savigne