I just noticed this term when I was freshing up with C++ FAQ.
In the case of member functions call, it will act upon the object which is used to call the function.
To achieve dynamic binding with friend functions, we have to make the interfaces as virtual to operate within the friend function. This is what we call ‘Virtual-Friend Function Idiom’. It’s not a big deal. Just don’t surprise on hearing this term next time.
See the sample snippet.
class Base
{
public:
virtual void print() const { cout << “base”; }
friend ostream& operator << (ostream& obj, const Base& b);
};
class Derived : public Base
{
public:
void print() const { cout << “Derived”; }
};
ostream& operator<< (ostream& obj, const Base& b)
{
b.print();
return obj;
}
int main()
{
Derived d;
cout << d;
return 0;
}