Export (0) Print
Expand All
Expand Minimize

Compiler Warning (level 1) C4669

'cast' : unsafe conversion: 'class' is a managed type object

The cast class contains managed extensions for C++. The compiler completes the cast by performing a bit wise copy of one pointer to the other, but provides no other checking. To resolve the warning, do not cast classes containing members with managed extensions.

The following sample generates C4669:

// C4669.cpp
// compile with: /clr /W1
#using "mscorlib.dll"

__gc struct A {
   int i;
   Object * pObj;   // remove the managed member to resolve the warning
};

__gc struct B {
   int j;
};

int main() {
   A *a = new A;
   B *b = reinterpret_cast<B*>(a);   // C4669
}
Show:
© 2015 Microsoft