0

dynamic memory

how we allocate dynamic memory ?

20th Jun 2018, 7:10 PM
Shaphine
Shaphine - avatar
5 Answers
+ 3
hinanawi It's not considered good practice to manually allocate and deallocate memory with those functions. C++ best practice to use smart pointers like unique_ptr and shared_ptr
20th Jun 2018, 11:58 PM
Maxwell Anderson
Maxwell Anderson - avatar
+ 1
malloc/free/realloc in C++ must be used ONLY for raw memory allocation while for objects you have to use new/delete
20th Jun 2018, 9:28 PM
KrOW
KrOW - avatar
0
for memory manipulation you would use malloc(), realloc(), and free(), if that's your question.
20th Jun 2018, 8:14 PM
hinanawi
hinanawi - avatar
0
ok thanks
21st Jun 2018, 6:06 AM
Shaphine
Shaphine - avatar
0
Actually i want help in program which consists of a class Pyramid. The class should contain a static data member “Pcount” which stores the total number of Pyramid’s objects. In the main() function, dynamically create three objects of Pyramid class and print the value of “Pcount”. Afterwards, delete any two objects of Pyramid and print the value of “Pcount” again. Can anyone help me with coding .
21st Jun 2018, 3:45 PM
Shaphine
Shaphine - avatar