Article ID: 240862 - Last Review: July 5, 2005 - Revision: 1.1 FIX: C2555 On Virtual Functions with Covariant Return TypesThis article was previously published under Q240862 On This PageSYMPTOMS
You can receive the following error message if you try to override a virtual function with a covariant return type:
error C2555: 'B::function' : overriding virtual function differs
from'A::function' only by return type or calling convention
CAUSE
The compiler does not support virtual functions with covariant return types as specified in the C++ Standard, section 10.3, which is quoted below:
5- The return type of an overriding function shall be either identical to the return type of the overridden function or covariant with the classes of the functions. If a function D::f overrides a function B::f, the return types of the functions are covariant if they satisfy the following criteria:
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This problem was corrected in Microsoft Visual C++ .NET. MORE INFORMATIONSteps to Reproduce BehaviorThe following sample code demonstrates the error: | Article Translations
|
Back to the top
