Using subclass type parameters in virtual functions

后端 未结 4 1270
甜味超标
甜味超标 2021-02-05 13:15

I have this piece of code (contrived from my real-life trouble)

It cannot compile, complaining ExtendsB does not implement B::Run(A* a). However, it has no

4条回答
  •  迷失自我
    2021-02-05 13:53

    It's simply two different types, which makes it two distinct functions with two distinct signatures.

    In general, if you're using a compiler that understands C++11, you should use the override keyword on functions that are intended to override another function. In your case, the error became apparent because of the abstract base class, but in other cases such an error can cause a lot of debugging...

提交回复
热议问题