Boost logo

Boost :

From: Peter (piotrus_at_[hidden])
Date: 2002-06-17 22:37:39


Is it possible to pass a pointer of a class member function into a thread ??
I have no problems passing functions (or pointers to functions rather) which
are not members of any classes. However when I try to pass member functions,
I get compile errors. I am using MSVS 6.0 on win 2000.

The following is a simplified model of my situation. I am trying to create a
thread inside a function of one class and pass into it, a pointer of a
member function of another class:

// all necessary includes;

class testClass1
{
public:
    // constructor
    testClass1() { // init code}
    ~testClass1() {}

    void fun1() { // some code}

};

class testClass2
{
  testClass2() { // init code}
    ~testClass2() {}

    // SEE HERE PLEASE
    void fun2()
    {
        // some code..

        boost::thread myThread(&object1.fun1) ; // PROBLEM HERE

        // more code...
    }

    testClass1 object1;
};

int main(int argc, char **argv)
{

    testClass2 class2;

    // some code...

    class2.fun2();

    // more code....

    return 0;
}

Any help would be greatly appreciated. Thanks in advance.

Peter


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk