rp*****@yahoo.com (Roland Pibinger) writes:
On 17 Nov 2006 11:18:18 -0800, "Puppet_Sock" wrote:
Gary Wessle wrote:
I am getting
task.cpp:109: error: argument of type 'void (Spac_task::)()' does not
match 'void* (*)(void*)'
Sure. You are trying to make a member function the thread function.
You can't. A thread function has to be static or global.
There are a few ways to deal with this. One is read the FAQ,
http://www.parashift.com/c++-faq-lit...o-members.html
I read the FAQ relating to this problem which is at
http://www.parashift.com/c++-faq-lit....html#faq-33.2
I am having hard time applying the principle to my problem.
the principle is:
// Wrapper function uses a global to remember the object:
Waiter* object_which_will_handle_signal;
void Waiter_memberFn_wrapper()
{
object_which_will_handle_signal->waiting();
}
int main(){
signal(SIGINT, Waiter_memberFn_wrapper);
}
how do I apply this to my code below?
************************************************** **************
#include <boost/thread/thread.hpp>
#include <iostream>
using namespace std;
class Waiter {
short customers_serv;
public:
Waiter(short);
void waiting();
void preform();
};
Waiter::waiter(short cs) : customers_serv( cs ) {
preform();
}
void Waiter::waiting(){
customers_serv--; // modify the object
cout << "serving " << customers_serv << " customers" << endl;
}
void Waiter::preform(){
boost::thread thrd( waiting );
thrd.join();
}
int main()
{
Waiter jack(5);
Waiter sofi(2);
}