Function with same name but different signature in derived class

前端 未结 2 1368
臣服心动
臣服心动 2020-11-22 03:14

I have a function with the same name, but with different signature in a base and derived classes. When I am trying to use the base class\'s function in another class that in

2条回答
  •  北海茫月
    2020-11-22 03:42

    Functions in derived classes which don't override functions in base classes but which have the same name will hide other functions of the same name in the base class.

    It is generally considered bad practice to have have functions in derived classes which have the same name as functions in the bass class which aren't intended to override the base class functions as what you are seeing is not usually desirable behaviour. It is usually preferable to give different functions different names.

    If you need to call the base function you will need to scope the call by using A::foo(s). Note that this would also disable any virtual function mechanism for A::foo(string) at the same time.

提交回复
热议问题