+ 2
What's the difference between this {MyClass obj; MyClass *ptr = &obj;} and this {Myclass *ptr=new Myclass}?....
C++ question
1 Respuesta
+ 2
*ptr = &obj
Here the pointer holds the address of an object allocated on the stack. You can also think of this as some sort of alias for your variable
*ptr = new Myclass
Here the pointer holds the address of an object allocated on the heap