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
Write a 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. The area under a curve between two points can b

#include #include #include void* memorycopy (void *des, const void *src, size_t count) {   size_t n = (count + 7) / 8;   char* destination = (char *) des;   char* source =

Rule: To determine the canonical form we should OR the min terms. A min term is defined as a Boolean equation of the input if the output is logic '1'. If the input is logic '1'

Structures A structure is a user-defined data type, which may have different data types as its members. Creating a structure is a two-part process. First, a structure template

Webcam Driver static library or DLL required for Windows I want a .dll or .lib file using which i will take a snapshot from the webcam and it can't turn on the webcam LED while

Write a program to calculate the average of ten numbers       #include stdio.h     /* Only this header is needed since only IO are used */     void main()     {          char

compose a C program to solve the equation z2=(p1/Pg)+(v1^2/2g)+z1 p1=100kpa,v1=2m/s z1=3m P=1000kg/m^3 define g=9.81


need an expert programmer to finish coding the requirements from the assignment withen 4 hrs

C Program for ADD,SUB,MUL,DIV,REM void main() {   int a,b,c,ch=0;           clrscr();           while(ch           { printf(" \n\n 1:- For To Add\n 2:- For