Archived

This topic is now archived and is closed to further replies.

steveharper101

Creating C++ Objects

Recommended Posts

steveharper101    122
I have seen two ways that objects can be declared from classes. Say the class name is CObject. One way is the standered way which i use: CObject Obj1; And the other is to use the new keyword: CObject *Obj1 = new CObject In a previous post I heard it said that the only diffrance is that when a object is instantiated with the new keyword it is allocated on the heap. What differance does this make and why would you want to instantiate an object on the heap? Are there any speed benefits? The only reason I could see for wanting to use the new keyword is if you wanted to declare an dynamic array of objects of type CObject Thanks Alot :-)

Share this post


Link to post
Share on other sites
Rube    122
Cause the heap is BIG =)

Say you were creating a huge array of objects, or if you objects required a lot of space, or both...you''d want to create them on the heap and avoid the limited stack memory. Also, with new you can create linked lists of objects and other data structures.

I won''t go too deep into it, sounds like you got the info and just wanted clarification, plus, this post will bring out a million text book responses.

R!

Share this post


Link to post
Share on other sites