Can I convert boost shared_ptr
to void*
and back to boost::shared_ptr
? I need this because I need to pass the shared pointer and a callback function to a timer function implemented in C. And in the call back I need to convert the void*
pointer back to boost:shared_ptr
. Doing so gave me errors.
I tried the same with a sample program.
#include <iostream>
#include <boost/shared_ptr.hpp>
using namespace std;
class A
{
public:
void f1() { cout<<"function f\n"; }
inx aa;
private:
};
void f2 (void *arg) {
boost::shared_ptr<A> b = ( boost::shared_ptr<A> *)(arg); //How to do this
}
int main ()
{
boost::shared_ptr<A> a (new A());
//void * ptr = (void *) &a;
f2( (&a));
return 0;
}
Can this be done with boost::shared_ptr
?
Just one more asterisk:
boost::shared_ptr<A> b = *(boost::shared_ptr<A>*)(arg);
boost::shared_ptr<A> *b = ( boost::shared_ptr<A> *)(arg);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With