Is it possible to perform reflection in c++, and instantiate a class given the name of it as a string?
Cheers,
Is it possible to perform reflection in c++, and instantiate a class given the name of it as a string?
Cheers,
There's no language feature that lets you do this. You can, however, write your own set of factory functions and put those in a string-indexed map.
If you can use MFC, it has a object serialization framework that allows you to do this. This is documented here. Just to clarify, MFC can be used for a UI less application and I have seen it being used in this way quite successfully.
If you can't use MFC, you can consider boost serialization library. But to my knowledge it does not provide a factory function that allows you to create classes given their names. However, it does have the mechanisms to dynamically create classes from their names which you may be able to adapt to your unique needs. The relevant doc is here.