By the Way. GetObject() returns an object, it's type was MyClass just not a pointer.
Never cast non-pointers to pointers. If the variable being returned is just an object, you need to first get that object:
MyClass myClass = GetObject();
Then you can get the address to that object, and assign it to a pointer.
MyClass *myPtr = &myClass;
...but you must be confident that 'myClass' lasts just as long as 'myPtr', or 'myPtr' will be accessing invalid information.
As soon as 'myClass' goes out of scope, the memory that 'myPtr' points to gets destroyed, but will sometimes appear to work under certain circumstances before biting you unexpectedly later.
With that understanding, you might see why this won't work:
MyClass *myPtr = &GetObject(); //Problem!
The value returned by GetObject() will only last until the end of that statement (the semicolon), which is why it needs to be copied into a real object, and not just a pointer or reference.
I think this post can be deleted safely.
Our posts and threads are preserved so others can learn from our mistakes as much as from our successes.