I have the below program where Derived class is inherited from Base class.
class Base
{
int p_var;
public:
virtual void function()
{
cout << "Function() of class Base"<<endl;
}
};
class Derived: public Base
{
public:
void function()
{
cout << "Function() of class Derived"<<endl;
}
};
class Another
{
int a_var;
friend void function();
};
void function(Base& base, Another& anot)
{
anot.a_var=base.p_var;
}
int main()
{
Base *bptr,bobj;
Derived dobj;
bptr=&bobj;
bptr->function();
bptr=&dobj;
bptr->function();
cin.get();
return 0;
}
In the above example I want to make "function()" a virtual member function of a "Base" class a friend to "Another" class. how should the syntax be?