0
Can anybody please explain the malloc function? I only know that it is used in dynamic memory allocation.
3 odpowiedzi
+ 2
Don't use malloc, it is from C. In cpp you need to use new/delete. new allocates dynamic memory for the object and calls its constructor. Returns a typesafe pointer to the allocated object. delete frees allocated memory.
MyClass *mc = new MyClass;
mc->myMethod ();
delete mc;
In modern cpp it's better to use smart pointer instead of manual deletion.
0
Thanks i'll use this first than reply u. Thanks buddy
0
You're welcome :)