I get C and pointers very well. But I'm trying to use C++ ~without~ standard pointers. It's working for the most part, but now I'm running into an issue:
// MyInterface &something = MyDummyBase(); is defined in the header as a private member
void MyClass::SetSomething(MyInterface &newSomething) {
something = newSomething;
}
MyInterface &MyClass::GetSomething() {
return something;
}
Now here's where it gets weird, from the caller:
1. myClassObj.SetSomething(AnotherClass());
2. MyInterface &Value = myClassObj.GetSomething();
At line 1, it calls the constructor of AnotherClass (as expected), sets something to AnotherClass (again, as expected), then calls the destructor of AnotherClass (not expected)
At line 2, it returns MyDummyBase instead. There are no lines inbetween.
All I can think, is that it considers AnotherClass() out of scope now, and destroys it. But what confuses me is, how does it know to revert back to MyDummyBase? I'm trying to do the equiv of .SetSomething(new AnotherClass()), but without raw pointers.
I'm assuming I have to explicitly declare AnotherClass outside of the method, and use it directly in the SetSomething method, but what happened with this logic confounds me.
Any ideas?
[Edit] Nevermind... it's not a pointer, so it can only be set in the constructor. Dur...