|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-12-21 15:31:29
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> >();
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net