#include "stdafx.h" using namespace System; ref class Base {}; ref class Derived : Base {} ; int main(){ Base^ b = gcnew Base(); Derived^ d = gcnew Derived(); try { d = safe_cast<Derived^>(b); } catch (InvalidCastException^ e) { } d = dynamic_cast<Derived^>(b); if (d == nullptr) { } }