Hi all,

What are the disadvantages to declaring a C++ class pointer without the new operator? E.g. situation 1:

Code:
MyClass* myClass;
Situation 2:

Code:
MyClass* myClass = new MyClass();
I understand that using the new operator declares the object on the heap instead of on the stack. However, when I first saw C++ all class pointers were declared without the new keyword. When I do this and compile with g++ with the -Wall option it gives the following warning:

Code:
warning: ‘myClass’ is used uninitialized in this function
Sorry if this is obvious; I've searched around a lot for the advantages and disadvantages and the only thing I can find is the bit about the stack vs. the heap, and that you need to delete any object created on the heap. Is using the stack somehow faster in terms of performance? If both ways are acceptable, why does g++ generate a warning?

Thanks!