RaouL RaouL - 1 year ago 79
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download