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


Different ways of declaring an Object

Recommended Posts

reaptide    226
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->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
dr_w0rd    122
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