|
Boost Users : |
Subject: Re: [Boost-users] How to cast a boost::shared_ptr to void*
From: Mupparthy Ravindranath (rv_nath_at_[hidden])
Date: 2011-05-10 04:54:26
Sorry for the spam. I got the answer, how to do it. Ignore my previous mail.
[quote]
#include <boost/shared_ptr.hpp>
#include <iostream>
using namespace std;
class A {
public:
void hello () { cout << "Hello, friends...!" << endl; }
};
typedef boost::shared_ptr<A> APtr;
void* callbk (void* o) {
APtr a = *static_cast<APtr*>(o);
a->hello();
}
int main() {
A* rawPtr = new A;
boost::shared_ptr<A>sPtr(rawPtr);
callbk((void*)&sPtr);
return 0;
}
[/quote]
warm regars,
RV
________________________________
From: Mupparthy Ravindranath <rv_nath_at_[hidden]>
To: "boost-users_at_[hidden]" <boost-users_at_[hidden]>
Sent: Tuesday, 10 May 2011 1:26 PM
Subject: How to cast a boost::shared_ptr to void*
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.
regards,
RV
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net