answersLogoWhite

0

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

13y ago

What else can I help you with?

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.


What are the merit and demerit of using friend function in c?

disadvantage of friend functions is that they require an extra lineof code when you want dynamic binding. To get the effect of a virtual friend,the friend function should call a hidden (usually protected:) virtual[20]member function.Read more: Demerits_of_friend_function

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.


Can there be friend functions in c plus plus?

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


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.


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 the difference between homoplasy and homologous structures in evolutionary biology?

Homoplasy refers to similarities in traits between different species that are not inherited from a common ancestor, while homologous structures are traits that are inherited from a common ancestor and have similar functions.


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 is the gerund phrase in This bill is for talking to my friend in Omaha.?

Yes, "talking to my friend" is the gerund phrase.


What is anatomically similar structure inherited from a common ancestor?

The pentadactyl limb structure, found in mammals, birds, reptiles, and amphibians, is inherited from a common ancestor. Despite modifications for different functions, such as wings in birds and flippers in whales, the underlying bone structure remains similar.


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.