answersLogoWhite

0


Best Answer

For the same reason that friends are not inherited in real life. Suppose Albert is a friend of Brian and Brian is a friend of Charlie. Would that then make Albert a friend of Charlie? No, of course it doesn't. They may well have a common friend in Brian, but that doesn't automatically make them friends of each other. And the same applies to classes; friends must be selected, never inherited.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why friend functions can not be inherited?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are the privileges granted to friend function?

Friend functions (and classes) have private access to the classes that declare them as friends. Although they have the same access rights as members of the class itself, friends are not themselves members of the class and cannot be inherited.


Which base class member functions are not inherited by a derived class?

Derived classes only inherit the protected and public members of their base classes. Private member functions cannot be inherited by a derived class.


What are the limitations of friend function?

Only that they cannot be inherited by derived classes. This is "a good thing". Other than that, a friend function has full access to a class' private and protected members and you cannot limit its scope.


What are the application of this pointer can you use this pointer in friend function justify?

The this pointer can only be used within nonstatic member functions. Friend functions are not members so they have no access to a this pointer. However, you can pass a specific instance of a class to a function via a class reference argument. To understand how friendship works, first understand that a nonstatic member function has the following properties: 1. It has private access to the class. 2. It is scoped to the class. 3. It must be invoked upon an object of the class (has a this pointer). Static member functions have the first two properties while friend functions only have the first property.


How does virtual function support run time polymorphism?

Virtual functions are used to suport runtime polymorphism.In C++,if we have inheritance and we have overridden functions in the inherited classes,we can declare a base class pointer and make it to point to the objects of derived classes.When we give a keyword virtual to the base class functions,the compiler will no do static binding,so during runtime ,the base class pointer can be used to call the functions of the derived classes.Thus virtual functions support dynamic polymorphism.

Related questions

What are the privileges granted to friend function?

Friend functions (and classes) have private access to the classes that declare them as friends. Although they have the same access rights as members of the class itself, friends are not themselves members of the class and cannot be inherited.


Why friend functions are not inherited in c plus plus?

Friend functions are not inherited because they are, by definition, friends of the classes in which they are declared. As such, a derived class must explicitly grant permission to a friend function, even when that function is a friend of the base class. Bear in mind that friends are highly-privileged -- so much so that I actively avoid using them wherever it is possible to do so. It may well be part of the language, and is sometimes the only the way to solve a problem, but it breaks the fundamental rules of encapsulation. Allowing a highly-privileged friend function to be inherited without your knowledge is a recipe for disaster -- every derived class from that point on would be exposed to it, rightly or wrongly. Hence you must explicitly declare the friendship, and only where it is deemed necessary.


Can there be friend functions in c plus plus?

Yes, there can be friend functions in C++.


Which base class member functions are not inherited by a derived class?

Derived classes only inherit the protected and public members of their base classes. Private member functions cannot be inherited by a derived class.


Why private data members or functions are not inherited?

Because that's what private means. Private data members or functions are intended to be usable only in the base class, and the inheriting class can only access protected or public members or functions.


How can you share friend functions between classes?

By inheriting the classes


What is an amigo phone?

A phone that functions not only as a phone.... but also a friend


How is working of a member function different from a friend function and a non-member function?

With respect to a given class, all functions can be split into four categories: 1. Member functions. 2. Static member functions. 3. Friend functions. 4. Non-member functions. All class member functions have the following three properties with respect to the class in which they are declared a member: 1. Private access to the class representation. 2. Scoped to the class. 3. Invoked through an instance of the class (has a 'this' pointer). Static member functions have the first two properties only. Friend functions have the first property only. Non-member functions have none of these properties.


What are the in-built function in c plus plus?

C++ built-in functions are those functions that are provided for you as part of the language itself, and includes all of the C standard library functions (all of which were inherited from C) and is expanded upon by the C++ standard template library. C++ implementors may provide additional functions that are platform-specific, however these are not considered built-in functions becuase C++ is a cross-platform language. These are best described as 3rd party functions. The functions you yourself write are known as user-defined functions.


What are the limitations of friend function?

Only that they cannot be inherited by derived classes. This is "a good thing". Other than that, a friend function has full access to a class' private and protected members and you cannot limit its scope.


Where can you find a Korean friend?

You can find Korean friends in Koreans gatherings. Facebook and the social functions.


What is inherited characteristic?

INHERITED CHARACTERISTICS