Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] Bind question for member functions
From: Anthony Williams (anthony_at_[hidden])
Date: 2009-01-08 12:23:54


At Thu 08 Jan 2009 17:15:58 UTC, David Eaves <ideaves_at_[hidden]> wrote:

> For example, when I specify the following, it should compile and work
> just the same as the simpler example, where count() has file scope. I
> took care to create local copies of the function ptr objects, as has
> been suggested in several threads. Since bind is supposed to create a
> copy of the function ptr, my creation of two local copies is probably
> overkill. But anyway, once the function pointer is to a member of foo
> instead of the simpler case, it will no longer compile.

> void (some_api_class::*fp1)(int) = &some_api_class::do_one_foo_task;
> boost::thread thrd1(boost::bind(fp1,1));

If you pass a member function, you need an object to bind it to. In
this case, an object of type "some_api_class". Try

boost::thread thrd1(boost::bind(fp1,&some_object,1));

Where some_object is an instance of some_api_class.

Anthony

-- 
Anthony Williams
Author of C++ Concurrency in Action | http://www.manning.com/williams
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk