Why is the virtual keyword needed?

前端 未结 4 1712
旧巷少年郎
旧巷少年郎 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:47

    One reason:

    Consider base classes located in separate module, like library.

    And derived classes in your application.

    How would compiler knows during compiling the library that the given function is/must be virtual.

提交回复
热议问题