473,396 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is there "reflect" solution in C++?

I just swtiched my working language from java to C++.
In java, there is one mechanism called reflect which enable us to have
knowledge of internals of a given class at run-time. That's one basic
mechanism used by JUnit.
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?
Jul 22 '05 #1
4 1533
Cheng Mo wrote:
I just swtiched my working language from java to C++.
In java, there is one mechanism called reflect which enable us to have
knowledge of internals of a given class at run-time. That's one basic
mechanism used by JUnit.
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'.

The longer answer is: some development suites support it, but the language
specification does not require reflection. There are many reasons for
this. The primary reason is the different nature of C++ verses Java. With
Java the use of a virtual machine and single inheritance from a universal
base class (the java.lang.Object class).

I certainly understand your desire to have introspection. Roumor has it,
Bjarne Stroustrup is working on some kind of introspection for C++, but
it's hush-hush.
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #2
"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.
Jul 22 '05 #3
"Andrea Savigni" <as******@acm.org> wrote in message
news:e5*************************@posting.google.co m...
"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/)).


Another tool that provides "compile time" reflection for C++ is
the DMS (http://www.semanticdesigns.com/Produ...SToolkit.html).
(DMS also provides source-to-source transformations
and program analyses in much easier-to-specify forms
than OpenC++).

One could, in principle, extract all this "reflection" information
and generate runtime tables that could answer runtime
reflection questions (this is in effect what Java does).
Without dynamic loading, however,
that doesn't seem very useful; any runtime question you
can ask can be answered effectively at compiletime
by such tools, and the results can be used to generate
code before compilation, which goes beyond what Java reflection does.
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com
Jul 22 '05 #4
"Ira Baxter" <id******@semdesigns.com> wrote
Another tool that provides "compile time" reflection for C++ is
the DMS (http://www.semanticdesigns.com/Produ...SToolkit.html).
(DMS also provides source-to-source transformations
and program analyses in much easier-to-specify forms
than OpenC++).

One could, in principle, extract all this "reflection" information
and generate runtime tables that could answer runtime
reflection questions (this is in effect what Java does).
Without dynamic loading, however,
that doesn't seem very useful; any runtime question you
can ask can be answered effectively at compiletime
by such tools, and the results can be used to generate
code before compilation, which goes beyond what Java reflection does.


Point is, there *is* dynamic loading in C/C++ on most platforms, in
the form of dynamic libraries (e.g., dlopen() and friends on unix,
LoadLibrary() and friends on windows). Under this respect, what you
can do in Java you can also do in C++ (even though in Java it is
admittedly easier on the programmer). However, one very interesting
thing you can do in Java is query an object of a previously (i.e., at
compile time) unknown class (loaded via forName()) about its
structure, methods, etc. and call said methods. In ordinary C++ you
can instantiate an object of a previously unknown class (assumed it
was linked as a DL) but you cannot query it nor much less so call its
methods (which of course you don't know about at compile time since
you don't even know about the object's class). I don't know about the
DMS, can you do such things even with dynamically loaded classes? If
so that actually sounds interesting.

Cheers,
a.
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Patrick | last post by:
Hello all! I am using a BufferedImage object to build an image from scratch. I want it to be a grayscale image with only 8bits of color. I have the color information as a byte, saved in variable...
7
by: Rui Pestana | last post by:
Hello all, I want to use the POST method to submit the form and then grab the parameters in the asp file with request.form("parm"). The problem is that I am using the _search target to open...
10
by: Fred | last post by:
There is a setting in INIT.ORA that has the unintended side-effect of making sure the ALTER SYSTEM KILL SESSION command has immediate affect. Without this setting, I've seen some instances where...
99
by: Jim Hubbard | last post by:
It seems that Microsoft not only does not need the classic Visual Basic developer army (the largest army of developers the world has ever seen), but now they don't need ANY Windows developer at a...
6
by: Sandman | last post by:
I'm having some problem here... I have a javascript I've downloaded that goes through all PNG files and enables the transparency channel in them for IE5.5+ by converting them to SPAN layers with...
9
by: Anders Borum | last post by:
Hello! I have a class that needs to validate the input value, when a programmer changes a specific property on a class. The input should only accept the following pattern {1,n} (alpha-numeric...
1
by: Dr. J | last post by:
I have an application that opens a socket and connects to another application listening over a port. The problem I am encountering is that when the listening application is closed my application...
21
by: Neel | last post by:
I am trying to "ping" a remote host in my C++/Redhat Linux code to check whether that host is connected or not. if (0 == system("ping -w 2 192.168.0.2)) But, in both cases...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.