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

With the struct definition given below…

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

Approach #1:

struct B : public A {
    virtual void hello() { ... }
};

Approach #2:

struct B : public A {
    void hello() { ... }
};

Is there any difference between these two ways to override the hello function?

9 Answers
9

Leave a Comment