Greetings,
The following code taken from an example compiles without errors:
#include
#include
#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
#include
#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::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