I have been building objects on the stack using the following constructor:

classname node(arg1, arg2);

Which worked fine.

But have now learned it is the heap I need to use.

So I need to use the new command I believe, but my syntax is wrong:

classname *ptr = new node(arg1, arg2);

But when I try this, it fails to compile.

Can you help?

Many thanks !

Si I have it working now using this code:

classname *ptr = new classname(arg1, arg2);

I'm a little confused now as I don't see 'node' in the pictures below, just 'ptr' using Visual Studio 2005.

Making the object on the stack:





Making the object on the heap:





This is the first time I've ever specified I want to use the heap instead of the stack.

Now I don't see 'node' in the heap screen shots.

Is it proper/normal practice to only access the object through the pointer now?

But what if the pointer drops off the stack? How will I later find the object to delete it later?

Really appreciate any guidance.