"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:<Wp********************@speakeasy.net>...
Cheng Mo wrote:
[...]
I was told that there is no reflect in C++. I am wondering whether or
not there is so solution to program out such feature.
Any ideas?
The short answer is 'no'.
[...]
Steven's reply is clearly correct. Let me just add a couple of
considerations.
Reflection as per the Java definition is actually more of a simple
introspection than full-fledged reflection (as you can find e.g. in
OpenC++ or OpenJava (see
http://www.csg.is.titech.ac.jp/~chiba/openc++.html and
http://www.csg.is.titech.ac.jp/openjava/)). Unfortunately, C++'s idea
of introspection (known as RTTI (Run-Time Type Investigation or
Identification or Information or...)) is even narrower. Forget about
e.g., obtaining a meta-class as you can do in Java, querying it for
method signatures and calling the methods. However, if you're after
really simple stuff such as getting to know the name of a type or
comparing types for equality, you can do that in C++ too (via the
typeid operator).
BUT...
The standard really leaves a lot to be desired in this field, and
dictates hardly anything even about the format of the type name to be
returned. So some compilers go all the way and produce a complete
class name with template parameters and all, while others emit little
more than garbage. This means that if you want to be portable you'd
better be extra careful while using that feature.
Regards,
a.