How to call a function by a string of name & How to get the name of a class?
-
There are hundred of similar classes and a large file(in processing)
with thousand of instances of these classes. I should export these
instances into a XML file (I use Tiny XML), however not total
instances, but these which belong to the selected classes and the
selected attributes(member variable and value). In advance, I will
have a configuration file (also XML format), to define which classes
and which attributes are selected, that is a user-defined file.
The problem are:1, How do I get the name of a class? Just like by Java the
method .getclass() or instanceof ?2, Is it possible to have such as an iterator to traverse through
all the variables/functions, to only call the functions and to get
the values of variables I need by name?Vielen Dank im Voraus!
-
For instance using "typeid" you can do this:
#include <iostream> #include <conio.h> #include <string> using namespace std; struct X { public: int a; }; class Y { }; int main() { int a; float b; double c; string d; X e; Y f; cout << typeid(a).name() << endl; cout << typeid(b).name() << endl; cout << typeid(c).name() << endl; cout << typeid(d).name() << endl; cout << typeid(e).name() << endl; cout << typeid(f).name() << endl; cout << typeid(e.a).name() << endl; getch(); }i f d Ss 1X 1Y i