how to make a vector to derivedClass::create() methods
Hi, I wish to make a std::vector to some create() methods from several different derived classes (same ABC). I could instead use the ctors if necessary. lambda::bind<> and lambda::constructor<> maybe?, but I fail getting syntax. Thank you, Vic
AMDG Victor.Whiskey.Yankee wrote:
I wish to make a std::vector to some create() methods from several different derived classes (same ABC). I could instead use the ctors if necessary.
lambda::bind<> and lambda::constructor<> maybe?, but I fail getting syntax.
I'm not really sure what you're trying to do. What exactly is the std::vector supposed to contain? std::vector<???> In Christ, Steven Watanabe
Steven Watanabe wrote:
AMDG
Victor.Whiskey.Yankee wrote:
I wish to make a std::vector to some create() methods from several different derived classes (same ABC). I could instead use the ctors if necessary.
lambda::bind<> and lambda::constructor<> maybe?, but I fail getting syntax.
I'm not really sure what you're trying to do.
What exactly is the std::vector supposed to contain? std::vector<???>
Thank you for your patience. I am really wanting to make a factory that holds a std::map where the pair.first is a std::string and the pair.second is somehow a pointer to a constructor or create() method to any of several derived classes>. I thought expressing in terms of vector might be simplified and enough for my understanding. Thank You! Vic
AMDG Victor.Whiskey.Yankee wrote:
Thank you for your patience. I am really wanting to make a factory that holds a std::map where the pair.first is a std::string and the pair.second is somehow a pointer to a constructor or create() method to any of several derived classes>.
I thought expressing in terms of vector might be simplified and enough for my understanding.
I see. How about using Boost.Function like this: std::map<std::string, boost::function<Base*()> > factory_impl; //... factory_impl["Derived1"] = boost::lambda::new_ptr<Derived1>(); // ... Base* b = factory_impl["Derived1"](); In Christ, Steven Watanabe
Mr. Watanabe, Thank you for your great help. It works well now. And thanks for helping everyone else so much on this list! -Victor Steven Watanabe wrote:
AMDG
Victor.Whiskey.Yankee wrote:
Thank you for your patience. I am really wanting to make a factory that holds a std::map where the pair.first is a std::string and the pair.second is somehow a pointer to a constructor or create() method to any of several derived classes>.
I thought expressing in terms of vector might be simplified and enough for my understanding.
I see. How about using Boost.Function like this:
std::map<std::string, boost::function<Base*()> > factory_impl;
//...
factory_impl["Derived1"] = boost::lambda::new_ptr<Derived1>();
// ...
Base* b = factory_impl["Derived1"]();
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Steven Watanabe
-
Victor.Whiskey.Yankee