Hi,

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:

Autos:

[IMG]http://i33.tinypic.com/9fyvyt.jpg[/IMG]

Locals:

http://i34.tinypic.com/291gorr.jpg


Making the object on the heap:

Autos:

[IMG]http://i36.tinypic.com/wve6hy.jpg[/IMG]

Locals:

[IMG]http://i33.tinypic.com/344uwxz.jpg[/IMG]

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.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.