Why must I re-declare a virtual function from an inherited class?

前端 未结 4 1114
长发绾君心
长发绾君心 2021-02-14 02:24

I\'m working on a simple C++ program and am having a difficult time understanding a compiler error I was getting. The issue was caused by me attempting to create a derived class

4条回答
  •  遇见更好的自我
    2021-02-14 03:05

    It doesn't work this way. You need to declare the methods you're going to define, whether they're overriding a virtual method or not.

    This isn't just an unreasonable requirement of the language. Without this you would be unable to define partially virtual class, i.e., you could have BaseSubtype that has common implementation of method1() but requires classes derived from it to implement method2() and method3()

提交回复
热议问题