I was wondering when we use Pointer to Pointer in C++ and why we need to point to a pointer? I know that when we point to a pointer it means we are saving the memory address of
Say you wanna instantiate an object in C++...
MyClass * obj = new MyClass();
You have to do this because new
returns a pointer to the allocated object in dynamic memory. The following would be wrong:
MyClass obj = new MyClass(); // wrong. 'new' returns a pointer.
Say you want an array of objects...
MyClass ** objArray = new MyClass*[10];