Virtual Friend Function
This talks about Virtual Friend Function in C++.
Friend functions are not in-herited in C++. So, to achieve dynamic binding with friend functions, we have to make the interfaces as virtual (make it as protected part of class) to operate within the friend function. This is what we call as Virtual-Friend Function.
Here is an example to explain the above concept.
Here, the function "operator <<" in main (Base& b) will invoke b.print(o), which is virtual. So here in main that Derived-print(o) will get control, as "b" is actually a object of class Derived.
Note here that "Derived" class overrides the behavior of the protected: virtual member function print(o) and it does not have its own implmentation for friend function "operator << (ostream& o, const Base& b)."
Re: Virtual Friend Function
Article of the month competition nomination started here
|All times are GMT +5.5. The time now is 10:15.|