I understand how this goes in the opposite direction. But for various reasons i want to use a base class object to call a derived class method
Let's say we have 2 classes, together representing a person's data (name and age) :
class Person
{
protected:
char* name; /// may be more than just one. also, heared that std::string is more efficient
public:
/// constructors, operator=, destructors, methods and stuff...
}
class Info: public Person
{
protected:
int age; /// may be more than one parameter.
public:
/// constructors, operator=, destructors, methods and stuff...
int get_age() const; /// method i want to call with a class Person object
{
return y;
}
}
Since those 2 classes are about a person's data, and i have a Person object, i want to use this object to find out his age as well ( likely calling the method get_age() from it's derived class, Info)
Saw something with pure virtual methods, but i don't know how to properly call that virtual function in main.
How can i do it ? (i will apreciate if you can show me the main of the program too).