Jump to content
  • Advertisement
Sign in to follow this  
himanojhere

function pointer container using Boost Bind

This topic is 3414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to call the function(consoleSetRenderMode()) once i get a string called "setRenderMode" but i get compilation errors :( #include <boost/any.hpp> #include <boost/function.hpp> #include <boost/bind.hpp> #include <map> #include <string> #include <vector> #include <iostream> using namespace std; typedef std::vector<boost::any> parameters; typedef boost::function<void(const parameters&)> consoleFunc; typedef std::map<std::string, consoleFunc> consoleFuncMap; consoleFuncMap consoleFuncs; void consoleSetRenderMode(const boost::any ); void consoleSetRenderMode(const parameters ¶ms) { assert(params.size() == 1); // should have 1 parameter int renderMode = boost::any_cast<int>(params[0]); cout<<"Val"<<renderMode<<endl; //renderer->setRenderMode(renderMode); } consoleFuncs["setRenderMode"] = boost::bind(&consoleSetRenderMode, _1);

Share this post


Link to post
Share on other sites
Advertisement
You don't need to use boost::bind if your function signature already matches the function type. However, since your function is overloaded, you do need to disambiguate the function overload. Ex:

consoleFuncs["setRenderMode"] = static_cast<void (*)(const parameters &)>(consoleSetRenderMode);

Share this post


Link to post
Share on other sites
Quote:

void consoleSetRenderMode(const boost::any );
void consoleSetRenderMode(const parameters ¶ms)

Two functions with the same name and different parameters are overloaded functions. Also, you can't assign elements in a map outside of a function like that. One way to deal with that is to move the assignments to inside main.

Share this post


Link to post
Share on other sites
No, your typedef for parameters is std::vector<boost::any>, not boost::any. And even if it was the same, the first one is by value and the second by reference.

Share this post


Link to post
Share on other sites
Quote:
Original post by himanojhere
to make the post look clear and short


Your definition of "clear" is defective.

Share this post


Link to post
Share on other sites
What was wrong with SiCrane's original response? That seems like the correct answer to me.
Quote:
Original post by SiCrane
Quote:

void consoleSetRenderMode(const boost::any );
void consoleSetRenderMode(const parameters ¶ms)

Two functions with the same name and different parameters are overloaded functions. Also, you can't assign elements in a map outside of a function like that. One way to deal with that is to move the assignments to inside main.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!