In C++ do you always have to initialize a pointer to an object with the new keyword?
Or can you just have this too:
MyClass *myclass;
myclass->DoSomething();
I thought this was a pointer allocated on the stack instead of the heap, but since objects are normally heap-allocated, I think my theory is probably faulty?
Please advice.
No, you can have pointers to stack allocated objects:
This is of course common when using pointers as function parameters:
One way or another though, the pointer must always be initialised. Your code:
leads to that dreaded condition, undefined behaviour.