0

there must be a simpler way ?? destructors not going well😕

16th Jul 2016, 6:35 PM
Afzaal Arif
Afzaal Arif - avatar
3 RĂ©ponses
+ 2
Before you dismiss destructors, pls try to understand them deeply. Destructors are not only used in C++, they are used in many object oriented languages. So how can I help you to understand destructors?
16th Jul 2016, 6:59 PM
Stefan
Stefan - avatar
0
In java destructors are called automatically. This is called garbage collector. But in CPP you have to call destructor. Ex. Class MyClass, then destructor ~Myclass(){}. Destroying a class, you can save memory.
6th Aug 2016, 2:34 PM
Sabbir Ahmed Shibli
Sabbir Ahmed Shibli - avatar
0
@Sabbir: What you said is either plain wrong or misleading. One doesn't have to call the destructor of a C++ object, normally. You can, however, but only on objects created by using "placement new" ("special" kind of new) you should. The destructor is automatically called when one frees an object that has been allocated on the stack, global / static storage or with a "normal" new on the heap. Using placement new, the destructor does not get called, so one should do it manually. In other cases it's called for you.
6th Aug 2016, 2:45 PM
Stefan
Stefan - avatar