Can anyone justify the statement: A virtual function can be declared as a friend of another class. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone justify the statement: A virtual function can be declared as a friend of another class.

Virtual and Friend function, cpp

18th May 2021, 3:08 PM
sourabh bhandari
sourabh bhandari - avatar
1 Answer
+ 1
It does not make sense at all. Friend function is function that is not declared as method and have access to protected/private members of a class. Virtual functions can only be member functions (aka methods). You can't have virtual non-member function. Quotation: "friend functions in C++ can not be declared virtual and therefore no dynamic binding of friend functions is possible."
18th May 2021, 5:16 PM
Michal Doruch