In a C++ class, I am trying to use shared_ptr, but instead of using this I am trying to use shared_from_this(). In the constructor, I am trying to create an object of a struct which expects a void*. I am not sure how I can convert a shared_ptr to a void* which can be passed as the parameters to the struct which is expecting void*.
Callback.cpp
struct CObj{
int val;
void* context;
};
class A : std::enable_shared_from_this<A>{
private:
Cobj mCobj;
public:
A(){
mCobj = (CObj){5, shared_from_this()};
}
~A(){
}
Cobj getObjref(){
return mCObj;
}
};
std::shared_ptr p = std::shared_ptr<A>(new A);
Cobj invokeCfunc = p->getObjref();