Skip to main content
gamedev.net
🔒 Locked

function pointer container using Boost Bind

Started by himanojhere Apr 16, 2009 at 4:27 PM 8 replies 1.2k views
Original Post
himanojhere
himanojhere
I am trying to call the function(consoleSetRenderMode()) once i get a string called "setRenderMode" but i get compilation errors :( #include #include #include #include #include #include #include using namespace std; typedef std::vector parameters; typedef boost::function consoleFunc; typedef std::map consoleFuncMap; consoleFuncMap consoleFuncs; void consoleSetRenderMode(const boost::any ); void consoleSetRenderMode(const parameters &params) { assert(params.size() == 1); // should have 1 parameter int renderMode = boost::any_cast(params[0]); cout<<"Val"<setRenderMode(renderMode); } consoleFuncs["setRenderMode"] = boost::bind(&consoleSetRenderMode, _1);
SiCrane
SiCrane
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);
SiCrane
SiCrane
Quote:

void consoleSetRenderMode(const boost::any );
void consoleSetRenderMode(const parameters &params)

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.
SiCrane
SiCrane
No, your typedef for parameters is std::vector, not boost::any. And even if it was the same, the first one is by value and the second by reference.
SiCrane
SiCrane
What exactly is the logic behind deleting all your replies here?
himanojhere
himanojhere
to make the post look clear and short
SiCrane
SiCrane
Quote:
Original post by himanojhere
to make the post look clear and short


Your definition of "clear" is defective.
himanojhere
himanojhere
can we get back to the problem
SiCrane
SiCrane
How? You deleted your responses. Kind of hard to comment on something that's not there.
Codeka
Codeka
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 &params)

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.