What's wrong with the language?

Pages: 12
helios wrote:
b.foo() can be resolved statically because B overrides non-virtually A::foo(). There's no chance b.foo() could call any other function. If B::foo() was virtual the compiler may still be able to make the call static, if B has no derived classes and B is not an exported type

A function that overrides a virtual function is always virtual. It doesn't matter if the virtual keyword is used or not.
If you want to say that a function cannot be overridden any further you can use the final keyword.

1
2
3
4
5
class B : public A{
public:
    void foo() final; // foo() is a virtual function that is not allowed 
                      // to be overridden by classes that inherit from B.
};
Last edited on
Topic archived. No new replies allowed.
Pages: 12