Virtual functions are an integral part of polymorphism in C++. To learn more, check our tutorial onC++ Polymorphism. Example 1: C++ virtual Function #include<iostream>usingnamespacestd;classBase{public:virtualvoidprint(){cout<<"Base Function"<<endl; } };classDerived:publicBase {public:voidprint...
The compiler first looks for thedisplay()function in classC. Since thefunctiondoesn't exist there, it looks for the function in classB(asCis derived fromB). The function also doesn't exist in classB, so the compiler looks for it in classA(asBis derived fromA). Ifdisplay()function exists...