answersLogoWhite

0

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.

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Can there be friend functions in c plus plus?

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


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 is the difference between cc plus plus and c sharp?

C# is inherited from c++ with some additional features


Printf and scanf Operators in C and C plus plus?

No, they are functions. Operators are -> or ++or /=


Why functions are not used in c plus plus?

Of course they are used. Both stand-alone and class-member functions are used in C++.


What is a method in c plus plus?

In C++, methods are simply class member functions.


What are the limitations of friend function in c plus plus?

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. At this data hiding feature of c++ is broken.


How many main functions are used in c plus plus program?

One.


How do you link a C plus plus program to C functions?

It should work without any special action.


Why does VisualStudio c plus plus not have an option to give functions It is in VS c Sharp?

Turn on the intellisense feature.


What are the pre-defined function in c plus plus?

The C++ standard library contains all the pre-defined functions.


What do you call the combination of variables and functions into a single object in C plus plus?

A singleton.