Point is the base class and ThreeD is the derived class. I would like to create a new object dynamically from the derived class via the following code:
Code:
int main()
{
Point *ptr = new ThreeD();
(*ptr).setXY(1,1); //base member function
(*ptr).setZ(1); //derived member function
(*ptr).display(); //polymorphic function
return 0;
}
The problem is that setZ(), a member function of the derived class, is unable to be called. Apparently the class created is that of the base class. What did I do wrong? Why isn't the object of the derived class?