Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / ForIn Loop C++

Author
Message
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 15th Apr 2011 16:03 Edited at: 15th Apr 2011 16:11
Hey,

Imagine you have the folowing class:



And I would want to output every variable dynamicaly.
So I would get this as output:



But I would want this also to happen when a new variable is added.

So if i add:



Without adding cout<<something[anyplace].a<<endl; or something.

A friend made it in Flash with a forin loop, ( NOT a normal for int loop) .

Is this possible in c++?

Cheers,

Leo

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 15th Apr 2011 18:12


Syntax may not be exact - bit toasted right now to think straight - but should be enough to give you an idea...

Regards,

JTK
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 16th Apr 2011 00:17 Edited at: 16th Apr 2011 00:17
Yeah, thats simply outputting all vars in the class.

I am talking about Reflection RTTI in C++. And creating debugger like Visual Studio's Debugger.

DeadTomGC
14
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 16th Apr 2011 04:16
I'm still learning how to use classes and pointers but maybe you could use a combination of these to do that.

Here is where I was reading about it.
http://www.cplusplus.com/doc/tutorial/classes/
Scroll down to "Pointers to classes".

Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 16th Apr 2011 11:47
I do know that all, the problem is that C++ takes away all properties of classes and variables in the compiled version. This means i dont have acces to variables names, altough in flash (which does have that, but makes it a slow programming language) all properties can be retrieved.

...like:



This would output any variable + value in the class object and show that on screen.

The easy way is the wrong way, which is couting every single variable on screen like. cout << object.x << endl; ... and so on.

Greets,

Leo

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 16th Apr 2011 17:06
Here's a link to Microsoft's page on reflection. It's specific to C++ .NET but as I don't know what you're looking to do with it, perhaps it pertains.

And here's a topic at stackoverflow where an individual has asked about Reflection in C++.

The short answer is that it can't be done without some significant macro magic going on behind the scenes. Right now, I'm under the assumption that you are using the VC++ Express edition. If that's not the case, check out how Microsoft's MFC classes do it. Basically, you have to create a base class (IUnknownClass) to inherit all of your custom classes from and use macros to add the information you need for later retrieval. C++ doesn't do this for you but you can do it yourself with macros.

If you don't want to go that route, you can check out the Debug Interface Access SDK but this requires that you include the debug information PDB file in the build of the application. I've used this method before myself. While it's not the most efficient way of getting the information you may be looking for, it may do you some good.

I hope this information is what you're looking for...

JTK
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 16th Apr 2011 20:15
Great points to start with! Thanks JTK!

Login to post a reply

Server time is: 2024-11-19 12:29:22
Your offset time is: 2024-11-19 12:29:22