473,609 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1550
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.Objec t 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******@setid ava.kushan.aa> wrote in message
news:<Wp******* *************@s peakeasy.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.o rg> wrote in message
news:e5******** *************** **@posting.goog le.com...
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:<Wp******* *************@s peakeasy.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******@semde signs.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
10194
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 name byte4. I have written the following code: First, thePanorama is defined as: new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Then I loop through like follows:
7
20912
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 the asp page. When I use _blank target there is no problem, either I use GET or POST method. But when I use _search target, only GET method works.
10
9767
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 the session reports as being KILLED in V$SESSION but is not physically removed until the instance is bounced. Does anyone remember this value offhand?
99
6064
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 small or mid-sized business. http://groups-beta.google.com/group/microsoft.public.msdn.general/browse_thread/thread/9d7e8f9a00c1c7da/459ca99eb0e7c328?q=%22Proposed+MSDN+subscription+changes%22&rnum=1#459ca99eb0e7c328 Damn! To be that...
6
6195
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 the image as background. This works great until I put one of these PNG files inside a display:none block and later sets the block to display:block - then the SPAN (that was the PNG <img>) remains hidden.
9
3491
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 with atleast one entry). I'm a little resistant to implementing a regular expression validation, because of the overhead involved (not because I can't :-). Obviously, it's possible to implement the pattern validation using regular string ops ..
1
16437
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 cannot detect it to take appropriate action. I am using "Connected" property of the Socket class, but it seems this property does not reflect the true state of the socket connection. Here is the code snippet. Basically, I am checking the...
21
30506
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 (connected/disconnected), system call returns 0. Can someone please show what I am doing wrong? How to check the actual result of the ping status using C++ on Redhat linux ? Thanks in advance.
169
9037
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 untaking to create a toolchain for it. Way back when, there used to be something called "Small C". I wonder if the creator(s) of that would want to embark on creating a nice little Small C++ compiler devoid of C++ language features that make...
0
8091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8232
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6064
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.