C++: Why does a struct\class need a virtual method in order to be polymorphic?

后端 未结 8 2135
庸人自扰
庸人自扰 2020-12-11 01:42

Following this question, I\'m wondering why a struct\\class in C++ has to have a virtual method in order to be polymorphic.

Forcing a virtual destructor makes sense,

8条回答
  •  情歌与酒
    2020-12-11 01:53

    Classes only need virtual methods in order to be dynamically polymorphic - for the reasons described by others. You can still have static polymorphism through templates, though.

提交回复
热议问题