Hi all to experts in programming C/C++ code.
I stumbled upon this code, but I’m confused what the 2 functions are returning.
Any kind souls could help me out?
I’ve tried to make the code as generic & useful to others as possible.
ClassA*& func1() {
static ClassA* mClassA;
return mClassA;
}
ClassA* func2() {
ClassA*& mClassA = func1();
if(!mClassA) {
... // omitted some code that fill mClassA with data.
}
return mClassA;
}
[edit] Also wanted to ask, do the *& in func1() and func2() cancel each other out?
returns the static pointer declared inside the method by reference. Doing:
would alter
mClassA.returns a copy of the pointer. It will point to the same memory, but changing the pointer doesn’t affect
mClassA.