16 Jan
2008
16 Jan
'08
4:11 p.m.
Elli Barasch wrote:
Is there a way I can "new" a copy of the shared_ptr onto the stack? Something like:
pthread_create(&t,&attr,&func,(void *) new shared_ptr<T>(shp));
The easiest way to do that would be to use Boost.Threads. void func( shared_ptr<T> p ); boost::thread t( boost::bind( func, shp ) ); If you need to use pthread_create, you might want to look at the source of Boost.Threads to see how it implements this functionality. That said, your suggested approach can also work; you'd need to cast the void* in func back to shared_ptr<T>* ppt and remember to delete it once you copy *ppt to a local shared_ptr variable.