Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is the difference between Friend Function and virtual function?

C# function Java virtual
0
Posted

What is the difference between Friend Function and virtual function?

0

They’re completely different beasts… 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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123