What Is The Difference Between Friend Function And Virtual Function?

1

1 Answers

Anonymous Profile
Anonymous answered
A friend function is a function that can access a class's private members while not being a member of that class. (You can also have friend classes)

A function is defined virtual so that polymorphism can work: If you have a pointer to the base class and invoke a virtual function, the derived class's version of the function is called. Without virtual functions you would have to cast a pointer to a base class to a pointer to a derived class to invoke the intended function.

Answer Question

Anonymous