C virtual:
class Base {
virtual void Foo() { std::cout << "Foo in Base" << std::endl;}
};
class Derived : public Base {
virtual void Foo() { std::cout << "Foo in Derived" << std::endl;}
};
Derived* d = new Derived();
d->Foo();
Base* b = new Derived();
b->Foo();
and without (same code, but leave it virtual):
Derived* d = new Derived();
d->Foo();
Base* b = new Derived();
b->Foo();
so the difference is that without virtualthere is no true polymorphism at runtime: which function is called is determined by the compiler depending on the current type of pointer / link through which it is called.
virtual (vtable), - , , . Foo Derived, , , Foo Base -.