Why is the virtual keyword needed?

前端 未结 4 1713
旧巷少年郎
旧巷少年郎 2021-01-13 07:17

In other words, why doesn\'t the compiler just \"know\" that if the definition of a function is changed in a derived class, and a pointer to dynamically allocated memory of

4条回答
  •  情深已故
    2021-01-13 07:29

    The compiler doesn't know, because it can't. It might be your intention, to not use virtual functions, because there's always a cost associated with every feature.

提交回复
热议问题