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

Srand and rand(), Mention clearly about srand and rand().

Mention clearly about srand and rand().

Random card generator, i need a program that generates this output: The hig...

i need a program that generates this output: The highest card wins! Suit Order is: clubs, diamonds, hearts and spades The computers card is the 5 of Spades. The player’s card is t

C program to string compression, C program to string compression: Writ...

C program to string compression: Write a program to define a sting and all operations on string. void main()                                 {

Program to spider''s path display to the screen, Spider webs have two types...

Spider webs have two types of silk, sticky silk and strength silk, spiders do not move on the sticky silken threads only on the strength threads. Assume one type of spider creates

Program to show the ascii value of characters, Program to show the ascii va...

Program to show the ascii value of characters: int main() {                 int one_char;                 cout                 one_char = getch();

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

Restart, how to create program in c that will system restart

how to create program in c that will system restart

OpenGL configured environment, 1. Using Visual C++ and your OpenGL co...

1. Using Visual C++ and your OpenGL configured environment, write an application that displays a “unique” graphical scene that you designed and coded for this course. What yo

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