Compiler Warning (level 1) C4303
'cast' from 'type1' to 'type2' is deprecated, use static_cast, __try_cast or dynamic_cast
C-style type casting or function-style casting is not supported when using Managed Extensions for C++. To cast, use either dynamic_cast Operator or static_cast Operator.
C4303 is not reachable using /clr and the new syntax; see C-Style Casts with /clr for more information.
The following sample generates C4303:
// 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);
}
}