I would like to get the exact terminology for the following in C++.
Please consider the following toy example:
class A{
public:
virtual void f(){ std::cout << "This is A" << std::endl; };
};
class B: public A{
public:
virtual void f(){ std::cout << "This is B" << std::endl; };
};
int main(int argc, char** argv){
A* ptr = new A(); //Base class pointer pointing to base class object
ptr->f(); //Base class method is called
delete ptr;
ptr = new B(); ////Base class pointer pointing to derived class object
ptr->f(); //Derived class method is called
delete ptr;
return 0;
}
The output is: This is A This is B
I would like to know the exact C++ terminology for this. Is it polymorphism or method overriding or something else?
The main thing is that I am using a base class pointer. When the pointer points to a base class object, the base class method is called. When it points to the derived class object, the derived class method is called, given the method is declared as virtual in both the classes.
Thanks