Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

final virtual functions in C++0x

Reading that you can have final virtual functions in C++0x I am bit confused. What is the difference to just omitting both modifiers in the first place?

like image 992
B_old Avatar asked Jul 22 '11 09:07

B_old


1 Answers

The difference occurs it's not the base that uses it, but the derived.

class Base {
    virtual void foo() = 0;
};
class Derived : Base {
    void foo() {} 
    // Still virtual because it's virtual in base- no way to "un-virtual" it

    virtual void foo() final {} 
    // Now un-overridable.
};

Think of it not as preventing overrides, but preventing "any more" overrides.

like image 89
Puppy Avatar answered Jan 03 '23 10:01

Puppy