Hello! I want to ask what happen, when I use virtual functions without pointers ? for example:
#include <iostream>
using namespace std;
class Parent
{
public:
Parent(int i) { }
virtual void f() { cout<<"Parent"<<endl; }
};
class Child : public Parent
{
public:
Child(int i) : Parent(i) { }
virtual void f() { Parent::f(); cout<<" Child"<<endl; }
};
int main()
{
Parent a(2);
Parent b = Child(2);
a.f();
b.f();
return 0;
}
^^ Why doesn't it work ? Where can I find something about how virtual methods really work?