polymorphism - C++: Why does a struct\class need a virtual method in order to be polymorphic? -
following this question, i'm wondering why struct\class in c++ has have virtual method in order polymorphic.
forcing virtual destructor makes sense, if there's no destructor @ all, why mandatory have virtual method?
because type of polymorphic object in c++ is, basically, determined pointer vtable, table of virtual functions. vtable is, however, created if there's @ least 1 virtual method. why? because in c++, never didn't explicitly ask for. call "you don't have pay don't need". don't need polymorphism? saved vtable.
Comments
Post a Comment