For example i have a class named "WaterScene", in the .xml i have saved as string "WaterScene" when i read the .xml i have to convert that string to class. One approach is just string comparison
if( string == "WaterScene")
return new WaterScene;
Is there any generic way to do this to avoid string comparison? Like in objective C(dynamic language) we can get the class using string...
Class classObject =[[NSBundle mainBundle] classNamed:string];
If all of the objects you would be returning are derived from a common base class, you could use a std::map<std::string,BaseClass *>
. The comparisons ultimately in there somewhere, but it keeps things better organized.
No, you can't do it with standard C++. C++ has no notion of reflection. Sorry :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With