I know how how to use the virtual method to implement runtime polymorphism. But I can't understand why the method receiver must be pointer or reference.
From my thoughts, base class and derived class both has a pointer point to function table, When declare a non-pointer base class variable, it's easy to let that variable instance pointer member point to derived class virtual function table, like this:
class Base{
public:
virtual void m1(){};
};
class Derived: public Base{
public:
virtual void m2(){};
};
int main(){
Base b = Derived(); // now b's hiding pointer point to Derived class virtual function table.
}
This is just a language standard rule or some technically reasons? Thanks advance!