Overloading operators in derived class

前端 未结 3 2020
粉色の甜心
粉色の甜心 2020-12-31 07:46

Must I need to redefine all the overloading operators with derived type if I require to use them in derived class?

The following code compiles fine:

         


        
3条回答
  •  不知归路
    2020-12-31 08:20

    What it means is that if Point had more than one operator+(), and you only redefined one of them, then only that one would be accessible in the derived class; the other overloads would be hidden. If you declare no operator+() in the derived class, then all of the parent ones are available; if you declare any in the derived class, then none of the parent ones are available.

    Make sense? This case is fine: the parent declares one, and you redefine that one. No problems. If the parent declared two, though, then your child class, which only declares one, would only have access to that one.

提交回复
热议问题