Can i explicitly call a destructor if i''ve allocated my , C/C++ Programming

Can I explicitly call a destructor if I've allocated my object with new?

Posted Date: 3/15/2013 5:35:42 AM | Location : United States





A: perhaps not.        

 Unless you utilized placement new, you must simply delete the object instead of explicitly calling the destructor. For instance, suppose you allocated the object through a typical new expression:

Fred* p = new Fred();

Then the destructor Fred::~Fred() will auto magically get called while you delete it via:

delete p; // Automagically calls p->~Fred()

You must not explicitly call the destructor, as doing so won''t release the memory which was allocated for the Fred object itself. Remember: delete p does two things: first it calls the destructor and second it deallocates the memory.

 

Posted by | Posted Date: 3/15/2013 5:36:19 AM


Related Discussions:- Can i explicitly call a destructor if i''ve allocated my , Assignment Help, Ask Question on Can i explicitly call a destructor if i''ve allocated my , Get Answer, Expert's Help, Can i explicitly call a destructor if i''ve allocated my Discussions

Write discussion on Can i explicitly call a destructor if i''ve allocated my
Your posts are moderated
Related Questions
I need vsti program Project Description: Knowledge of vsti programs, and music is a plus, ex: nexus I will input the sounds I just need the interface built Skills required

c-program to find the area under the curve y=f(x) between x=a and x=b integrate y=f(x) between the limits of a and b   #include float start_point, /


Hiding overloaded functions We cannot overload a base class function by redefining it in a derived class with a dissimilar argument list. Consider examples to see if similar fu

Write a program called A1Q3, that reads it the radius of a circle as an integer and prints the circle's diameter, circumference and area.  Use a constant value for pi.  Do all calc


Hi I''m trying to connect to CISCO router using termios. So I decided to have two threads one for reading data and the other one for writing data. The problem is that I have to add

Why are all header files not declared in every C program? - Declaring all header files in each program would result in increase in overall file size and load of the program. It

Purpose This assignment is an exercise in implementing the queue ADT using a singly-linked list. This assignment also introduces the concept of templates. Assignment Th

program that generate university statistical bar graph using 3d function