Hi, I haven't been able to work out if the following is possible or how to do it from reading the documentation or from my searches.
I have 2 overloaded methods defined like this, which compiles OK: int foo(sigc::slot<void, Glib::ustring *> activity_slot); int foo(sigc::slot<bool, Glib::ustring *> timed_slot); However when passing a functor like this: foo(sigc::mem_fun(*this, &Activity::callback)); The compiler errors because it is unable to choose between the candidates. Error is: cc-test-0017.cc: In member function ‘void Activity::run()’: cc-test-0017.cc:68: error: call of overloaded ‘foo(sigc::bound_mem_functor1<void, Activity, Glib::ustring*>)’ is ambiguous cc-test-0017.cc:34: note: candidates are: int foo(sigc::slot<void, Glib::ustring*, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>) cc-test-0017.cc:40: note: int foo(sigc::slot<bool, Glib::ustring*, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>) Is it possible to make this work or will I have to rename the overloaded functions to be different? Thanks, Mike Here's the complete test case extracted from the real code showing the problem I am having. /* FILE : cc-test-0017.cc * * SYNOPSIS: Test ambiguous overloaded functions with sigc::slot. * BUILD: g++ -o cc-test-0017 `pkg-config --cflags --libs glibmm-2.4` cc-test-0017.cc */ #include <iostream> #include <stdlib.h> #include <glibmm/main.h> #include <glibmm/ustring.h> #include <sigc++/slot.h> int foo(sigc::slot<void, Glib::ustring *> activity_slot); int foo(sigc::slot<bool, Glib::ustring *> timed_slot); int foo_internal(sigc::slot<void, Glib::ustring *> activity_slot, sigc::slot<bool, Glib::ustring *> timed_slot); class Activity { void run(); void callback(Glib::ustring * str); }; class Timed { void run(); bool callback(Glib::ustring * str); }; sigc::signal<void> my_signal; int foo(sigc::slot<void, Glib::ustring *> activity_slot) { sigc::slot<bool, Glib::ustring *> empty_timed_slot; return foo_internal(activity_slot, empty_timed_slot); } int foo(sigc::slot<bool, Glib::ustring *> timed_slot) { sigc::slot<void, Glib::ustring *> empty_activity_slot; return foo_internal(empty_activity_slot, timed_slot); } int foo_internal(sigc::slot<void, Glib::ustring *> activity_slot, sigc::slot<bool, Glib::ustring *> timed_slot) { Glib::ustring activity_message = "activity"; Glib::ustring timed_message = "timed"; sigc::connection c; if ( ! activity_slot.empty() ) c = my_signal.connect(sigc::bind(activity_slot, &activity_message)); else if ( ! timed_slot.empty() ) c = Glib::signal_timeout().connect(sigc::bind(timed_slot, &timed_message), 500 /*ms*/); //do stuff if ( c.connected() ) c.disconnect(); } void Activity::callback(Glib::ustring * str) { std::cout << "void Activity::callback(*str=\"" << *str << "\")" << std::endl; } void Activity::run() { foo(sigc::mem_fun(*this, &Activity::callback)); } bool Timed::callback(Glib::ustring * str) { std::cout << "bool Timed::callback(*str=\"" << *str << "\")" << std::endl; } void Timed::run() { foo(sigc::mem_fun(*this, &Timed::callback)); } int main(void) { return EXIT_SUCCESS; } _______________________________________________ libsigc-list mailing list libsigc-list@gnome.org https://mail.gnome.org/mailman/listinfo/libsigc-list