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.
Different ways of declaring an Object
Hello everyone,
I have always declared new objects by declaring a pointer of that object and then allocating new memory to it, alla:
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".
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".
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement