why they always use
class_name *pointer = new class_name(arg)
class_name object = new class_name(arg)
im sorry im learning c++ after c# which makes this kinda confusing to me
the first we create pointer to a new object then we use it to access member/method
the second we create the object striaght then use it directly
what is the difference ? do i got it right ? which is more efficient ?
In C++ class objects can be defined either in stack or in heap. In C# class objects always are allocated in heap.
In C++ you should yourself delete objects created in heap. in C# it is the garbage collector that removes objects from the heap.
So consider the following C++ code that would not use pointers
MyClass obj2 = new myClass();
How will you distinguish obj1 and objj2 whether the object requires to be deleted or not?
i still didn't get what you said at the end and the difference between them (sorry the book im using is too dry)
which expression in c++ create in heap and which create in stack ? and which is better or what is the use of both ?
and i duno the answer of the last question , please lemme know if you don't mind
thank you so much :)