On Tue, May 10, 2011 at 8:56 AM, Mupparthy Ravindranath <rv_nath@yahoo.com> wrote:
Hi all,

My requirement is to cast an object of type shared_ptr as void*, so that I can send it to a callback function that accepts a void*.  I cannot change callback the function signature because it is part of an existing legacy code.

In the existing code, I am sending a raw object pointer (instead of shared_ptr).  Now, if I want to pass a shared_ptr, it won't compile because I cannot cast the shared ptr to void*. 

Can anyone suggest some workaround for this.  I tried searching the mailing lists and internet, but not much luck.



struct X { };
boost::shared_ptr<X> p;
void f( void *);

f( p.get( ) );

should do it. But beware the pointee may be deleted if the last copy of the shared pointer
goes out of scope, as the raw pointer won't have incremented the reference count.

- Rob.