On 12/19/07, Andrew Holden
STenyaK (Bruno Gonzalez) [stenyak@gmail.com] wrote: typedef shared_ptr<MyClass> pMyClass; void* MyClass::actionThread(void *objectPointer) { MyClass * _obj = static_cast
(objectPointer); pMyClass obj = _obj->shared_from_this(); obj->action(false); } void MyClass::action(bool threaded) { if (threaded) { pthread_t tid; pthread_create(&tid, 0, actionThread, this) } else { //TODO: actually perform the action } } ----------------------------
This works because shared_from_this is specifically designed to allow member functions of a class to recover the shared pointer to the object.
Just in case... actionThread is a static method of the class, since otherwise C++ won't allow me to get a pointer of it (and i dislike global functions). Does this fact have any implications in the last proposed code sample? Thanks again to everybody. -- Saludos, Bruno González _______________________________________________ Msn/Jabber: stenyak AT gmail.com ICQ: 153709484 http://www.stenyak.com