Polymorphism interfaces in C++
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?
Re: Polymorphism interfaces in C++
It uses a special pointer table called a vtable where it stores pointers to virtual methods (such as the destructor) associated with an object and the table travels with the object during its whole lifespan.
Re: Polymorphism interfaces in C++
lol. I forgot about that. xD. Thanks mate.