using namespace win32::gui::draw; // pointer to a surface ptr<> p = ...; // Casting using namespace surface; // it throws if the cast fails ptr<fill> f = cast<fill>(p); // f2 is null, if the cast fails ptr<fill> f2 = try_cast<fill>(p);