|
Boost Users : |
From: Guillermo Martony (gmartony_at_[hidden])
Date: 2004-05-10 09:12:05
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
{
public:
thread_alarm(int secs) : m_secs(secs) { }
void operator()()
{
boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec += m_secs;
boost::thread::sleep(xt);
std::cout << "alarm sounded..." << std::endl;
}
private:
int m_secs;
};
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:
#include <fstream>
#include <boost/thread/thread.hpp>
#include <boost/thread/xtime.hpp>
#include <iostream>
class thread_alarm
{
public:
thread_alarm(int secs) : m_secs(secs) { }
void operator()()
{
boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec += m_secs;
boost::thread::sleep(xt);
std::cout << "alarm sounded..." << std::endl;
}
private:
int m_secs;
std::fstream fs; // only this line was added
};
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;
}
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
]
I'm using Microsoft Studio .NET 2002
Thanks in advance for any help.
Guillermo Martony
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