Public Group

# overloaded function with boost function arguments

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

## 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 on other sites
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 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 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));}

• 15
• 9
• 13
• 41
• 15