RaouL RaouL - 6 months ago 32
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.