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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -