RaouL RaouL - 2 months ago 9
C++ Question

Different methods for instantiating an object in C++

What is the difference between this:

Myclass *object = new Myclass();


Myclass object = new Myclass();

I have seen that a lot of C++ libraries like wxWidgets, OGRE etc use the first method... Why?


The second is wrong !

You may use

MyClass object;

That will work.

Now, concerning how to choose between these two possibilities, it mainly depends on how long your object should live. See there for a thorough answer.