C++ “virtual” keyword for functions in derived classes. Is it necessary?

后端 未结 9 1493
遇见更好的自我
遇见更好的自我 2020-11-22 15:17

With the struct definition given below...

struct A {
    virtual void hello() = 0;
};

Approach #1:

struct B : public A {
           


        
9条回答
  •  长情又很酷
    2020-11-22 15:36

    Adding the "virtual" keyword is good practice as it improves readability , but it is not necessary. Functions declared virtual in the base class, and having the same signature in the derived classes are considered "virtual" by default.

提交回复
热议问题