0

I have some callback functions :

class someclass
{
  private:
  bool someCB1(GdkEventFocus*,GtkEntry*);
  template<class T> bool someCB2(GdkEventFocus*,T*);
};

somewhere in the code of someclass I have a Gtk::Entry* entry. If I connect someCB1 :

entry->signal_focus_out_event().connect( sigc::bind<Gtk::Entry*>( sigc::mem_fun( this, &someclass::someCB1 ), entry ) );

this one works, but in my case I want to use someCB with different kinds of Gtk::Widget, so I wrote the template function someCB2

to connect someCB2 I wrote :

entry->signal_focus_out_event().connect( sigc::bind<Gtk::Entry*>( sigc::mem_fun( this, &someclass::someCB2 ), entry ) );

this line failed at the compilation, errors are very numerous (I cannot scroll my console to the first one, but the last ones are similar, so I guess like the rest). Here the last one :

/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:6356:1: note:   template argument deduction/substitution failed:
/home/user/chicken.cc:158:111: note:   couldn't deduce template parameter ‘T_arg1’
   entry->signal_focus_out_event().connect( sigc::bind<Gtk::Entry*>( sigc::mem_fun( this, &someclass::someCB2 ), entry ) );

can someone tells me what I mess ?

The Unholy Metal Machine
  • 1,093
  • 2
  • 17
  • 36
  • 1
    You have exactly the same problem as [him](http://stackoverflow.com/questions/32016749/forwarding-arguments-to-template-member-function) (although it's a different usage) you can solve this by explicitly telling the compiler which `someCB2` you want to use (I mean, with which types) [Edit: also, I have the feeling you're trying to use templates to achieve dynamic polymorphism, that won't work, use virtual methods for that] – Caninonos Aug 14 '15 at 22:21
  • @Caninonos actualy I don't see how I can tell wich type to choose (all my tries fails) – The Unholy Metal Machine Aug 14 '15 at 22:32
  • @Caninonos thx for your participation – The Unholy Metal Machine Aug 14 '15 at 23:49

1 Answers1

2

When you use &someclass::someCB2 the compiler has no chance to deduce what type T should be when using it with mem_fun(). If the address of the class is directly used with something allowing to deduce the template argument it would work.

In your case you probably want to use something like the below instead:

 static_cast<bool (someclass::*)(GdkEventFocus*, GtkEntry*)>(&someclass::someCB2)

Alternatively you can also specify the template argument directly:

&someclass::someCB2<GtkEntry>
Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380
  • Ah, too slow, i shouldn't have done something else :p Well at least: [example](http://ideone.com/5HTimW) (with dummy signals/slots, no encapsulation because I'm lazy and it's not relevant here) – Caninonos Aug 14 '15 at 23:03
  • @Dietmar Kühl thank you. Actualy when I read `&someclass::someCB2` I was of course... call me `esel`... I don't write template very often and I forget the place of the `` I tried by adding it before `someclass` and `someCB2`... – The Unholy Metal Machine Aug 14 '15 at 23:48