When i develop a destructor, do i require to explicitly call, C/C++ Programming

Assignment Help:

When I develop a destructor, do I require to explicitly call the destructors for my member objects?

 

 


Related Discussions:- When i develop a destructor, do i require to explicitly call

Functions, differentiate between inbuilt and user defined functions

differentiate between inbuilt and user defined functions

M - algorithm corrections, Of course it is C[i] = A[i] + B[i].It was a typi...

Of course it is C[i] = A[i] + B[i].It was a typing mistake,never mind. You just understand the concept. 27-1 b. for grain-size=1 n=A.length grain-size=1 r=n for

Change to palindrome, A palindrome is a string that reads the same from bot...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Described multiple inheritance(virtual inheritance)?, Described multiple in...

Described multiple inheritance(virtual inheritance)? And explain its advantages and disadvantages? A: It is the procedure in which a child can be derived from more than one pare

Program for stack over flow vulnerability., Imagine that the server program...

Imagine that the server program is a setuid program owned by the root, then after you penetrate the program with a shell running, you become the ROOT and you can remove the whole f

Write a haskell program, Write a Haskell program that calculates a balanced...

Write a Haskell program that calculates a balanced partition of N items where each item has a value between 0 and K such that the difference between the sum of the values of first

Wap to calculate total marks and percentage of 3 subjects, WAP TO ACCEPT MA...

WAP TO ACCEPT MARKS OF THREE SUBJECT FOR STUDENT & CALCULATE TOTAL MARKS AND PERCENTAGE #include stdio.h> #include conio.h>   void main() {            int M1,M

Explain manipulators, Manipulators There are several classes in the ios...

Manipulators There are several classes in the iostream.h header file. One of them is ios class. This class stores the format state. For example, some bits explain the base in w

Model view controler, store the name of the political parties and the corre...

store the name of the political parties and the corresponding votes in two lists of equal length. access the lists is provided by two methods, each of which creates an interator th

Operators and their expression in cpp, Operators in C++: All C operator...

Operators in C++: All C operators are valid operators in C++ also.  Besides C++ has developed some new operators like Operators and their Expression: 1.      Logical op

3/15/2013 5:38:38 AM

A: No. You never have to explicitly call a destructor (except with placement new).

A class''s destructor (whether or not you explicitly describe one) automatically invokes the destructors for member objects. They are destroyed in reverse order they show in the declaration for the class.

class Member {               

public:

~Member();

...

};

class Fred {

public:

~Fred();

... private: Member x_; Member y_; Member z_;

};

Fred::~Fred()

{

// Compiler automagically calls z_.~Member()

// Compiler automagically calls y_.~Member()

// Compiler automagically calls x_.~Member()

}

 

3/15/2013 5:39:30 AM

A: No. You never require to explicitly call a destructor (except with placement new).

A derived class''s destructor (whether or not you explicitly define one) automagically invokes the destructors for base class sub objects. Base classes are destructed after member objects. In the event of multiple inheritances, direct base classes are destructed in the reverse order of their appearance in the inheritance list.

class Member {

public:

~Member();

...

};

class Base {

public:

virtual ~Base(); // A virtual destructor

...

};

class Derived : public Base {

public:

~Derived();

... private: Member x_;

};

Derived::~Derived()

{

// Compiler automagically calls x_.~Member()

// Compiler automagically calls Base::~Base()

}

Note: Order dependencies along with virtual inheritance are trickier. If you are relying onto order dependencies within a virtual inheritance hierarchy, you''ll require many more information than is in this

 

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