Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Reflection in c++ (http://www.go4expert.com/forums/reflection-in-cpp-t17532/)

SaswatPadhi 15May2009 09:58

Reflection in c++
Can someone guide me on achieving Reflection in C++ ?

It can be done easily in C# or Java, as they have built-in reflection facilities, but how do I do it in C++. I googled a lot but didn't find anything significant. :(

shabbir 15May2009 10:16

Re: Reflection in c++
It is possible to have reflection in C++ but then it should be done manually and not automatically.

I have done this for my last job but before I explain what I did I would explain why it could not be done.

When you compile Java / C# programs and convert them into binaries they are not actual binaries which can be run directly on the CPU containing language understood by the CPU but they contain instruction which can be understood by the intermediate language ( JVM or anything you call it )

Now when you compile the C++ code you actually generate Assembly language code which means it does not have the definition for function classes but actually all being converted.

This is the main reason why reverse engineering is also not possible to the full in C++ but its very much an option in Java and C#.

Now the question comes how to do reflection in C++.

What I saw is when you create dll in C++ you can use the dll viewer to check out the functions defined in dll and so it met me thought that some Meta Data about the dlls are contained within the Dll.

So what I did is for certain set of dll I had same function which helped me get lot of things out of that dll.

Say I have a function

And then it lists me all the things that I need outside of that dll and that way you can try out but there are some limitations to it as well.

Say you want a class object to be used in the calling function from the dll and for that at times you may need the .h file in both application.

SaswatPadhi 15May2009 10:35

Re: Reflection in c++
Thanx for the quick reply shabbir :pleased:

I just found this article (through Google) and it seems quite useful :

shabbir 15May2009 11:43

Re: Reflection in c++
Yes really nice one and quite inline of what I have suggested.

All times are GMT +5.5. The time now is 19:13.