![]() ![]()
Without the friend function, we will require the object of these classes to access all the members. We might require a function, metro(), to access both these classes without any restrictions. To understand this better, let us consider two classes: Tokyo and Rio. This is only the case when we do not want to use the objects of that class to access these private or protected members. Use of Friend function in C++Īs discussed, we require friend functions whenever we have to access the private or protected members of a class. A class’s function definition does not use either the keyword friend or scope resolution operator (: □.įriend function is called as function_name(class_name) and member function is called as class_name. We can define the friend function anywhere in the program like a normal C++ function. In the above declaration, the keyword friend precedes the function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |