I weren't surprised when found that I can use base-class pointers for usage to derived classes like this (very simple):
class Base
{
protected:
int m_value;
public:
Base(int value)
: m_value(value)
{
}
const char* getName() { return "Base"; }
int getValue() { return m_value; }
};
class Derived: public Base
{
public:
Derived(int value)
: Base(value)
{
}
const char* getName() { return "Derived"; }
int getValueDoubled() { return m_value * 2; }
};
What is happened after an object derived class has been created? If I use
Base &rBase = derived;
I'll use such methods that is determined in base class. Why? Does it mean that derived class actually consists first-determined getName() of Base class, but for now uses only overloaded method and if we want then we can call origin method by pointer on base class? Explain me please in terms of pointer and addresses.