Sorry to correct in part the reply of coder777... I know I am not a programmer, but he didn't notice a thing.
The original question said:
> why they always use
> class_name *pointer = new class_name(arg)
> pointer->member()
>
> instead of
> class_name object =
new class_name(arg)
> object.member()
As far as I know the second form is completely wrong. "new" operator allocates memory for a new object, and return the memory address of that object (so it returns a POINTER).
The object will survive until it will destroyed with "delete".
The correct way to create a local object (a true object to be used through value) is another one, and that one showed by coder777
1 2
|
class_name obj(arg); // This is a local variable which is destroyed when the function ends
obj.member()
|
This form is the correct way to create a "real" object to be used directly (without need to be dereferenced with ->). This object will be local, so it will be destroyed when fuction will end.
All things said by coder777 are right, however