Re: [orbitcpp-list] question about ORBit-tools
Status: Beta
Brought to you by:
philipd
|
From: Phil D. <ph...@us...> - 2000-05-18 12:21:36
|
Ronald Garcia wrote:
>
> hey guys,
> got a question about some code I found in orbitcpp_tools.hh.
>
> There is some code which goes like so:
>
> #ifdef ORBITCPP_HAVE_BAD_CAST
> #define ORBITCPP_NARROW_OR_NULL(type,item) \
> type *result; \
> try { \
> result = dynamic_cast<type *>(item); \
> } \
> catch (bad_cast) {\
> result = NULL; \
> }
> #else
> #warning ORBit-C++ will not detect narrowing errors on pseudo objects.
> #define ORBITCPP_NARROW_OR_NULL(type,item) \
> type *result = static_cast<type *>(item);
> #endif
>
> a few questions/comments:
>
> 1) In C++, dynamic casting to a pointer type doesn't throw
> exceptions, it just returns a 1. bad_cast is thrown on dynamic casts
> to references...ie, I don't think that code will work.
>
I don't think the dynamic cast thing will work at all, since it requires
rtti information AFAIK, and we're using reinterpret_casted C objects
which won't have this information (since no vtable etc..). Andreas?
Cheers,
Phil.
|