Sign in to follow this  

boost function conversion woes

Recommended Posts

Suppose I have
typedef boost::function<void (double,double)> voidFunct_2dbl;
typedef boost::function<void ()> voidFunct_void;

    TriggerBrush* AddAction(voidFunct_2dbl newaction);
    TriggerBrush* AddAction(voidFunct_void newaction);

The compiler claims that the call to AddAction is ambiguous, even though neither type can be converted to the other. What can I do?

Share this post

Link to post
Share on other sites
Can you post the code that's actually generating the error?

I probably couldn't answer your question without doing some experimentation and/or research myself, but if you're trying to pass in an arbitrary function object, the compiler would (presumably) have to try to resolve the ambiguity by trying to match the argument with function's own constructor template. Whether or not it can do this, I'm not sure (again, I'd have to research it a bit).

If you're just looking for a solution though, I imagine that if you were to make the boost::function typedefs public (if they're not already) and then call AddAction() like this:
Then that would resolve any possible ambiguity.

Share this post

Link to post
Share on other sites
Here's the code that generates the error

myManager->AddEntity((new TriggerBrush(myManager, 70,0,1540,768, false))

class trigStartColossusFight
const entitymanager_ptr myManager;
const cf_collmanager_sptr myCFmanager;

trigStartColossusFight(entitymanager_ptr targetmanager, cf_collmanager_sptr collisionmanager);

void operator()(double arg1, double arg2);

Share this post

Link to post
Share on other sites
Hm, I'm afraid I don't have any insights beyond what I mentioned earlier. My best guess is still that the compiler, for whatever reason, isn't able to resolve the ambiguity by way of the function constructor template.

I may be overlooking something though - maybe someone else will spot this thread and provide some additional feedback. In the absence of a better answer though, I'd recommend just giving the functions different names, or trying my previous suggestion (that is, making the argument type explicit so as to resolve the ambiguity).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this