Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error C2555

' class1::function1': overriding virtual function return type differs and is not covariant from 'class2::function2'

A virtual function and a derived overriding function have identical parameter lists but different return types. An overriding function in a derived class cannot differ from a virtual function in a base class only by its return type.

To resolve this error, cast the return value after the virtual function has been called.

You may also see this error if you compile with /clr. For example, the Visual C++ equivalent to the following C# declaration:

Guid[] CheckSources(Guid sourceID, Guid[] carouselIDs);


Guid CheckSources(Guid sourceID, Guid carouselIDs[]) [];

For more information on C2555, see Knowledge Base article Q240862.

The following sample generates C2555:

// C2555.cpp
// compile with: /c
struct X {
   virtual void func();
struct Y : X {
   char func();  // C2555
   void func2();   // OK

Community Additions

© 2015 Microsoft