Jump to content
  • Advertisement
Sign in to follow this  
Storyyeller

overloaded function with boost function arguments

This topic is 2857 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 have two constructors in a class, which both take a callback, but with a different signature.


Foo(boost::function<void (Uint32)> cb);
Foo(boost::function<void (Uint32, Uint32)> cb);



My compiler says that this is ambiguous for some reason, and I can't figure out why. For now I've solved it by adding a dummy argument, but this is not an ideal solution.

Share this post


Link to post
Share on other sites
Advertisement
Forgive me if this is wrong, I may be completely off base, but to me that reads as basically the same signature. Since the only real parameter of Foo is a boost function (I'm not sure what the void (Uint32) bit does as I've not used boost, but that appears more to do with the boost::function which is the parameter of Foo, as oppose to the Uint32's which are paramter's of the boost::function. If that makes any sense.

As I said, I may be completely off base, but I assume your dummy argument reads like this:

Foo(boost::function<void (Uint32) cb, int SomeDummy);

This to be is definitely different from the two you showed earlier.

Share this post


Link to post
Share on other sites
But aren't templates classes with different arguments supposed to count as different types? I thought that only Java had type erasure.


Edit: Apparently Boost function does have type erasure for some reason. I guess I'm forced to use dummy arguments then.

Share this post


Link to post
Share on other sites
Works just fine for me. MSVC 2010:

#include <boost/function.hpp>

typedef unsigned int Uint32;

void Foo(boost::function<void (Uint32)> cb) {}
void Foo(boost::function<void (Uint32, Uint32)> cb) {}

void foo(Uint32) {}

int main(int, char **) {
Foo(boost::function<void (Uint32)>(&foo));
}

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!