Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Warning (level 1) C4303
Collapse the table of content
Expand the table of content

Compiler Warning (level 1) C4303

Error Message

'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) {

Community Additions

© 2015 Microsoft