+ 10
What is the main reason of using a friend class?
Anyone please!
13 odpowiedzi
+ 8
to access private data members with a non-member function
+ 4
it's when you are lazy enough to not think with inheritance in mind
+ 3
thanks!
+ 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.
+ 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.
+ 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++
+ 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.
0
Thanks so much!
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
0
friend function used to access private data
0
if you want to use private access specifier outside the class then with the friend member function you access private property of class.
0
Para poder tener acceso a miembros privados de una clase