so I have 3 classes
main class which stores a pointer
struct Main {
int * p;
A subclass1, subclass2;
void init()
{
subclass1.init(p);
subclass2.init(p);
}
};
and two subclasses
struct A {
int * p;
void init(int * ap)
{
p = ap;
}
};
Now I would like to create a pointer from subclass1 or subclass2 that will actually create a pointer in Main class, so subclasses can use the same int from main class
heres what im trying to achieve
in first scenario you see same windows so you see that on phone1 and phone2 theres a blue wireframed object that im trying to share between multiple windows, but when I change projection window I cant see it, so I need a shared pointer
https://youtu.be/9HLDsrm7R2w
I already messed with int ** p; for subclasses but im missing something (maybe because int * p in main class is 0)
and I cant assign it by int ** subp = (*mainclass.p);
if someone tells me that I could use shared ptr then I ask him to provide some example code for me cause I never used it and have no xp with it.
However pointer to pointer c style would be the best approach for me thus theres something wrong in the code I dont fully understand so far, int * p in main class has to be 0 until its not created by subclass...
maybe I somewhere use it where I shouldnt, well I just changed the code from * to ** and just switched from if (p ==0) return;
to if ( (*p) == 0) return; etc.
but theres few thousands lines I need to check so a short brief of handling such types would be appreciated..