[orbitcpp-list] question about ORBit-tools
Status: Beta
Brought to you by:
philipd
|
From: Ronald G. <rga...@pi...> - 2000-05-17 23:36:59
|
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.
2) I looked at the code to set ORBITCPP_HAVE_BAD_CAST in
acinclude.m4... as far as I recall, in g++, bad_cast can be found in
<typeinfo> instead of <exception>. I think this is the wrong place
according to c++ standards, but if we're going to use it, we might as
well support the most common compiler for this stuff.
3) I think that the above could be implemented as a template,
n'est-ce pas? That would be the c++ way
just wondering what's thought about that...
ron
|