
21 Dec
2007
21 Dec
'07
1:31 p.m.
Nat Goodspeed:
The issue I mentioned above keeps recurring across different projects: given a string from a file or a script, I need to instantiate a distinct C++ class corresponding to that string. I mention an abstract base class because I don't know how, other than virtual functions, I should access the features of such an object.
I would dearly love to see the best way to leverage boost::factory to address this problem. If, in the process, I learn new tricks myself, all the better!
Typically you'll have something like std::map< std::string, boost::function<std::auto_ptr<A>()> > s_factory; where A is your abstract base, and initialize s_factory with s_factory[ "X" ] = boost::factory< std::auto_ptr<X> >();