Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2004-05-10 14:16:37


Guillermo Martony <gmartony_at_[hidden]> wrote:
> Greetings,
> The following code taken from an example compiles without errors:
>
> #include <boost/thread/thread.hpp>
> #include <boost/thread/xtime.hpp>
> #include <iostream>
> class thread_alarm
> {
<snip>
> };
>
> int main()
> {
>     int secs = 5;
>     std::cout << "setting alarm for 5 seconds..." << std::endl;
>     thread_alarm alarm(secs);
>     boost::thread thrd(alarm);
>     thrd.join();
>     return 0;
> }
>
> But adding a std::fstream varible to the thread_alarm class:
<snip>
> Results in the following compilation error:
>
> c:\opt\include\boost\function\function_template.hpp(289):
> error C2664: 'void
> boost::function0<R,Allocator>::assign_to(Functor)' : cannot convert
> parameter 1 from 'const thread_alarm' to 'thread_alarm'
>         with
>         [
>             R=void,
>             Allocator=int,
>             Functor=thread_alarm
>         ]

The boost::thread constructor copies its argument, so the thread_alarm
class needs to be copiable, but std::fstream is not copiable. You
might be better off using Boost.Bind to produce a lightweight functor.


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