I've been using C++ for quite some time. But I never really asked how it knows to do this.

void
Foo::bar(BarInterface *bary) {
delete *bary;
}

and say somewhere else you have like

class FooBar : public BarInterface {
};

How does it know to call FooBar's constructor if it's cast into BarInterface first before deleting?