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

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -