c++ - dynamic_cast macro rescue NULL -
i want use dynamic_cast
intrinsic in generated c++ code. macro definition looks like:
#define jcast(t, v) (dynamic_cast<t*>(v))
unfortunately, because code generated, situation can occur:
foo(jcast(uwiseobject, null));
a compiler said that:
error: `nullptr_t` not pointer.
how can rescue null
in situation? want like:
if (v) return dynamic_cast<t*>(v); else return null;
well, that's macro's you. write real c++ instead:
template<typename t, typename u> t* jcast(u* u) { return dynamic_cast<t*>(u); } template<typename t> t* jcast(nullptr_t) { return nullptr; }
Comments
Post a Comment