Advertisement Jump to content


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


Creating C++ Objects

This topic is 6218 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Cause the heap is BIG =)

Say you were creating a huge array of objects, or if you objects required a lot of space, or''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.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!