Hello, I have a class A containing two pointers to objects of another class B. I want to initialize one pointer or the other depending on which one is passed to init(), which also takes other parameters. My situation is thus the following:
class A {
public:
A();
init(int parameter, int otherParameter, B* toBeInitialized);
protected:
B* myB;
B* myOtherB;
};
Now my point is that I want to call init() as:
init(640, 480, this->myB);
or
init(640, 480, this->myOtherB);
Now, my init is implemented as:
void init( int parameter, int otherParameter, B* toBeInitialized ) {
toBeInitialized = someConstructorFunction(parameter, otherParameter);
}
The problem is that the two pointers are not initialized, I suspect that toBeInitialized is overwritten, but the original parameter is not modified.
I am doing something wrong?
Should I use references to pointers?
Thank you
Tommaso