C++ Pointers and Object Instantiation

c++, instantiation, new-operator, object, pointers

Solution

The keyword `new` returns a pointer. It must be assigned to a pointer of an object.

This would also work:

MyObject o = MyObject();

EDIT:

As Seth commented, the above is equivalent to:

MyObject o;

The default constructor (i.e. without parameters) is called if no constructor is given.

Problem

This works: ``` MyObject *o; o = new MyObject(); ``` And this does not: ``` MyObject o = new MyObject(); ``` Why?

Original source