Boost logo

Boost Users :

Subject: Re: [Boost-users] [Bind] Does not compile with local classes
From: Dmitry Bufistov (dmitry_at_[hidden])
Date: 2009-07-15 06:05:30


Rudi Dittrich wrote:
> Hello,
>
> I tried to use a local class as a callback function registering with a boost signal. The example below shall illustrate this scenario. There are two classes: class Foo which triggers a signal when its member function set_k( k ) is called. Each object which wants to receive this signal has to subscribe with it, calling on_k_changed(...). The second class is Bar which has one member function change_k(...). There is a local class KChanged inside this member function. KChanged has one function k_changed(...) which shall be called whenever the signal in Foo is triggered. Thus, it shall act as a callback function. Therefore, I used boost bind with k_changed(...) and tried to register with Foo's signal. After compiling I get the following compilation error:
> g++ -Wall -o local_class local_class.cpp -lboost_signals
>
> In member function ‘void Bar::change_k(uint32_t)’:
> nested_function.cpp:56: error: no matching function for call to ‘bind(void (Bar::change_k(uint32_t)::KChanged::*)(uint32_t), Bar::change_k(uint32_t)::KChanged*, boost::arg<1>&)’
>
> I do not really understand why this doesn't work. If I make k_changed(...) static then it works and I do not get any compilation errors. So my questions are:
> 1.) Is this a compiler problem? I use g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)

I vote for this.

Dmitry


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net