Boost logo

Boost Users :

From: Mark Storer (mstorer_at_[hidden])
Date: 2002-06-18 11:45:33

This has little to do with boost (which, again, is why I can answer; at
least in part)

A member function cannot be addressed like a regular function. Ask yourself
this question: With just a function pointer to go by, what will the
compiler use for 'this'?

The Good News: STL contains a template functor to take care of this for you:
"std::mem_fun". I haven't messed with it personally, but the docs sure make
it sound like it would do the trick.

The Bad News: I'm not so sure the thread class will let you use it.

I'm not familiar with the function0<> template, so I don't know whether or
not std::mem_fun will work with boost::thread.

Anybody care to chime in here?

--Mark Storer
  Software Engineer
  Cardiff Software

#include <disclaimer>
typedef std::disclaimer<Cardiff> Discard;

-----Original Message-----
From: Peter [mailto:yg-boost-users_at_[hidden]]
Sent: Monday, June 17, 2002 9:09 PM
To: boost-users_at_[hidden]
Subject: [Boost-Users] boost::threads queation

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
    // constructor
    testClass1() { // init code}
    ~testClass1() {}

    void fun1() { // some code}


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

    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...


    // more code....

    return 0;

Any help would be greatly appreciated. Thanks in advance.


Info: <>
Wiki: <>
Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at