RaouL RaouL - 1 month ago 5
C++ Question

Different methods for instantiating an object in C++

What is the difference between this:

Myclass *object = new Myclass();


and

Myclass object = new Myclass();


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

Answer

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.