Why is the override specifier preferred on a derived virtual function?
Correct answer
A. It turns a would-be silent non-override, such as a missing const or a wrong parameter type, into a compile error
14 views
A. It turns a would-be silent non-override, such as a missing const or a wrong parameter type, into a compile error
14 views
override is a compile-time assertion that the function really overrides a base virtual, so a signature mismatch that would otherwise create a new overload and break polymorphism becomes a hard error. It is often combined with final, which blocks further overriding in deeper classes. It neither creates virtuality, which comes from the base declaration, nor affects inlining.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.