override keyword
Steven Schveighoffer
schveiguy at yahoo.com
Thu Nov 27 07:12:21 PST 2008
"Zarathustra" wrote
> When 'override' is so really required?
The grammar of your question is ambiguous, but I'll try to explain override.
The override keyword *requires* that the function is an override of a base
class' virtual function. Not using the override will still override the
virtual function, but if you put override it will fail to compile if there
is no virtual function to override.
This isuseful, for example, if you are inheriting from a base class, and
that base class changes the signature of a function that you chose to
override, the compiler flags it as a failure. This way, you can see what
was affected by the base class change. If you did not use the override
keyword, then the code would still compile, but the new base class function
would not be overridden, giving you potentially a disasterous silent bug.
For this reason, many people have suggested requiring the override keyword
to override virtual functions. But currently, it is still optional.
Hope this helps.
-Steve
More information about the Digitalmars-d-learn
mailing list