Jump to content
  • Advertisement

Archived

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

reaptide

Different ways of declaring an Object

This topic is 5980 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

Hello everyone, I have always declared new objects by declaring a pointer of that object and then allocating new memory to it, alla:
  
CObject *Object;
Object = new(CObject);

Object->DoSomething();
Object->Stuff = Thingy;
  
The only reason I really do this is because I prefer to use the -> operator to access members of the object instead of the . operator. What I wanted to know is if there is any real difference between declaring an object the way I do it or as you would for any other variable.

Share this post


Link to post
Share on other sites
Advertisement
It''s generally bad idea to make code design decisions based on whether you like to write ''A'' better than ''B'', or in this case ''->'' better than ''.''.

In this case though, I don''t think there''s any real difference.

When declaring object you should think if you want it to exist in certain stack frame and if you really NEED a pointer to the object or not, and base your decision on that, rather than which seems "more fun to use".

Share this post


Link to post
Share on other sites
You will be fine as long as you rember that when you dynamically allocate memory via ''new'', you must ''delete'' it when you are finished with it.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!