-1

I want to use a dynamic_cast intrinsic in my generated C++ code. The macro definition looks like:

#define jcast(T, v) (dynamic_cast<T*>(v))

Unfortunately, because the code is generated, this situation can occur:

foo(jcast(UWiseObject, NULL));

A compiler said that:

error: `nullptr_t` is not a pointer.

How can I rescue NULL in this situation? I really want something like:

if (v) 
    return dynamic_cast<T*>(v);
else
    return NULL;
Netherwire
  • 2,669
  • 3
  • 31
  • 54

1 Answers1

4

Well, that's macro's for 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; }
MSalters
  • 173,980
  • 10
  • 155
  • 350