Compilerwarnung (Stufe 1) C4303

Aktualisiert: November 2007

Fehlermeldung

'Typumwandlung' von 'Typ1' zu 'Typ2' ist veraltet. Verwenden Sie static_cast, __try_cast oder dynamic_cast
'cast' from 'type1' to 'type2' is deprecated, use static_cast, __try_cast or dynamic_cast

Die C-Typ- oder Funktionsformatumwandlung wird bei Verwendung von Managed Extensions for C++ nicht unterstützt. Verwenden Sie für die Typumwandlung entweder den dynamic_cast-Operator oder den static_cast-Operator.

C4303 ist mit /clr und der neuen Syntax nicht erreichbar. Weitere Informationen finden Sie unter C-Style Casts with /clr.

Im folgenden Beispiel wird C4303 generiert:

// C4303.cpp
// compile with: /clr:oldSyntax /W1
__gc struct A { };
__gc struct B { };

int main() {
   B *b = new B;
   try {

   // C4303 old 'c' style cast
   A *a = (A*)b;   // C4303
   // run time exception becaused casting to incompatible types

   // try the following line instead
   // A *a = __try_cast<A*>(b);
   } 

   catch (System::InvalidCastException * e) {
      System::Console::WriteLine(e);
   }
}