Megosztás a következőn keresztül:


C2392 fordítási hiba

"method1": a kovariant visszatérési típusok nem támogatottak felügyelt vagy WinRTtype típusokban, ellenkező esetben a "method2" felülbírált lenne

Megjegyzések

A Covariant visszatérési típusai nem engedélyezettek a Windows Futtatókörnyezet tagfüggvényeihez, illetve a /clr (Common Language Runtime Compilation) beállítás összeállításakor.

Example

Az alábbi példa c2392-t hoz létre, és bemutatja, hogyan javítható ki.

// C2392.cpp
// compile with: /clr
public ref struct B {
public:
   int i;
};

public ref struct D: public B{};

public ref struct B1 {
public:
   virtual B^ mf() {
      B^ pB = gcnew B;
      pB->i = 11;
      return pB;
   }
};

public ref struct D1: public B1 {
public:
   virtual D^ mf() override {  // C2392
   // try the following line instead
   // virtual B^ mf() override {
   // return type D^ is covariant with B^, not allowed with CLR types
      D^ pD = gcnew D;
      pD->i = 12;
      return pD;
   }
};

int main() {
   B1^ pB1 = gcnew D1;
   B^ pB = pB1->mf();
   D^ pD = dynamic_cast<D^>(pB);
}