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

Assignment Help:

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


Related Discussions:- Can i explicitly call a destructor if i''ve allocated my

Luminous Jewels - The Polishing Game, Byteland county is very famous for lu...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Program to display the greatest common divisor , Many modern cryptography a...

Many modern cryptography algorithms require two numbers that are coprime, or sometimes referred to as relatively prime. Two numbers are coprime if their greatest common divisor is

How can i provide printing for whole hierarchy of classes?, A: Provide a fr...

A: Provide a friend operator class Base { public: friend std::ostream& operator ... protected: virtual void printOn(std::ostream& o) const; }; inline std::ostr

Define dangling pointer?, A: A dangling pointer arises while you use the ad...

A: A dangling pointer arises while you use the address of an object after its lifetime is end. It may occur in situations such as returning addresses of automatic variables from a

How to implement tr- 106 protocol, Environment - C, Linux Duration - De...

Environment - C, Linux Duration - December 2006 to Feb 2007 Description - TR-106 specifies a generic data model template applicable for all TR-069 enabled devices. Adde

AREAUNDERCURVE, Write a program to find the area under the curve y = f(x) b...

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 betw

Exceptions handling in cpp, Exceptions. Your SVector class should throw fou...

Exceptions. Your SVector class should throw four exceptions: 3.1. If the constructor size is invalid, then it will just allow the implicit STL bad_alloc exception to pass up to mai

Describe difference between malloc()/free() & new/delete?, for object, mall...

for object, malloc allocates memory in heap however doesn't invoke object's constructor to initialize the object. new allocates memory & also invokes constructor to initialize the

Explain union, Unions A union is also like a structure, except that onl...

Unions A union is also like a structure, except that only single variable in the union is stored in the allocated memory at a time. It is a collection of mutually exclusive var

How does a structure differ from an array, Question : (a) What is a str...

Question : (a) What is a structure? Provide a simple example of your own to illustrate this feature. (b) How does a structure differ from an array? (c) Describe a structu

3/15/2013 5:36:19 AM

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.

 

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd