Suppose, the same function is defined in both the derived class and the based class. Now if we call this function using the object of the derived class. Compiler will call which function and elaborate the same used by the compiler.
#include<iostream>
using namespace std;
class Base
{
int x;
public:
virtual void fun() = 0;
int getX() { return x; }
};
// This class inherits from Base and implements fun()
class Derived: public Base
{
int y;
public:
void fun() { cout << "fun() called"; }
};
int main(void)
{
Derived d;
d.fun();
return 0;
}
Comments
Leave a comment