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

In this lab, please complete a given program to perform the following tasks: 1. Allocate a 10 by 5 2D byte array dynamically. The way of allocation must be consistent with pag

This problem familiarizes you with using random numbers in C++. The program is to compute a good approximation of π using a simulation method called "Monte Carlo". The following fi

algorithm to find out all the factors of given positive integers

A: No. Syntax wise it is permitted. But then the function is no longer Inline. Since the compiler will never know how deep the recursion is at compilation time.

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes


My file pointer is going to the location which i specified and writing the value but it is in next line so,please help me iam developing in visual studio6

I am seeking an expert to create a 360 degree virtual tour in KRPano for use on PCs, tablets and smartphones. You will be given with panoramas in order to create an advanced KRPano

Develop Diablo 2 LOD 1.13d Dupe Method for Closed Battle.net This hack is for diablo 2 lord of destruction The program must work on all realms, all cores, all ladders (4x rea