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 we will take a closer look at the logic behind Object Oriented Programming.  Read through the pseudocode listed below and answer the following questions. Class Square

What about Virtual Destructor? describe it.

Programming Assignment #3: Vehicle Track Performance Tests Purpose: The purpose of this programming assignment is to give the student experience in using functions, arrays, and str

What happens while a derived-class object is developed & destroyed? A: Space is allocated (on the heap or the stack) for the full object (i.e. adequate space to store the data m

Static Variables Static variables have the similar scope s automatic variables, but, unlike automatic variables, static variables retain their values over number of function ca

We need an E Commerce site likefifacointrader. you must have experience with that kind of work You have to show a sample of work like that site. Skills required are C Prog


develop a C program for Linux called pipes.c that does the following: In the main() function, it creates a pipe using the pipe() function, then creates two child processes with

What are the benefits of using friend classes? - Friend classes are useful when a class wants to hide features from users which are required only by another, tightly coupled cl

Define the Data Type Modifiers in C language? There are three data types(int, float & double) above have the following modifiers. 1. short 2. long 3. signed 4. unsigned