How do we store a pointer that was passed by reference to get modified in C++?
class A {
private:
reference_to_a_pointer_; ???
bool useSpecialAPI_;
public:
void useSpecialAPI(mytype_t *&recvd_data);
void init();
};
void A::useSpecialAPI(mytype_t *&recvd_data)
{
useSpecialAPI_ = true;
reference_to_a_pointer_ = recvd_data; ???
}
void A::init()
{
if (useSpecialAPI_) {
// specialAPI() returns a "void*"
reference_to_a_pointer_ = (mytype_t *)specialAPI();
}
}
In main(), I'm doing,
int main ()
{
mytype_t *recvd_data = NULL;
A a;
a.useSpecialAPI(recvd_data);
a.init();
if (recvd_data) {
parseData(recvd_data);
}
return 0;
}
I'm passing recvd_data pointer by reference, for it to get populated in init() function later. I would need to store it in the class member variable. How can I store it and assign it a value later?
I would like to avoid modifying or overloading the prototype of init()
.