Re: [gtkmm] syntax for MenuElem( .....,slot( static member function ) )



>>>list.push_back( MenuElem("Start" ,slot(my_cc,  &Control_class::playback) ) )
>;
>
>That works if my_cc is a menu but I can't get it to work if it is a non-menu c
>lass.  
>
>Also if use a global variable:
>
>Control_class *cc_ptr;
>
>main()
>{
>   *cc_ptr = new Control_class;
>
>    ...
>}
>extern Control_class *cc_ptr;
>my_menu_class::my_menu_class()
>{
>   
>
>...list.push_back( MenuElem("Start",slot(*cc_ptr,&(cc_ptr->playback) )));
>}
>
>I get a message that says something to the effect that I can't make a pointer 
>out of the address of a member function of a "bound variable".
>
>However I can make a "wrapper" function in my_menu_class called playCb()  whic
>h is just:
>
>extern Control_class *cc_ptr;
>int my_menu_class::playCb
>{
>    cc_ptr->playback();
>}
>
>and use
>    
>      list.push_back( MenuElem("Start", slot( *this, &playback) ));
>
>and get things compiled. (Don't know if this runs correctly yet.)
>
>
>I am mystified by what can go into slot() and what cannot.  Of course, I've ne
>ver studied Gtk.

nor C++, from the look of it.

you cannot take form a pointer to a member function by using an
instance of the class. it has to be of the form:

       &ClassName::method_name 

and be supplied with an instance of the class. 

thats why:

>>>list.push_back( MenuElem("Start" ,slot(my_cc,  &Control_class::playback) ) )

works, but:

>...list.push_back( MenuElem("Start",slot(*cc_ptr,&(cc_ptr->playback) )));

does not.

--p



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]