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

Minimumshelf, Write a program that finds the minimum total number of shelve...

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

Program to display appropriate message-clients accounts, Question A ban...

Question A bank normally updates it's clients accounts at the end of each month.Of the two types of bank accounts:savings and checking, a client must maintain a minimum balance

C++ programming, give a program to accept and print 2_D Array

give a program to accept and print 2_D Array

Valid segments 1, Consider text comprised of sentences and sentences compri...

Consider text comprised of sentences and sentences comprised of words. Words in a sentence will be space delimited. Given a text and K strings, task is to find out the number valid

Program to develope dating service to form couples, In this assignment, you...

In this assignment, you will develop a program named "match" to be used by a dating service to form couples. Given the number of gentlemen, the number of ladies, and a list of acce

Determine the size of operator, The size of () operator This is a pseud...

The size of () operator This is a pseudo-operator given by the language, which returns the number of bytes taken up by a variable or data type. The value returned by this opera

Make qtav videoplayer simple integrateable for application, Make QtAV Video...

Make QtAV Videoplayer simple integrateable for Qt Applications Project Description: I'm preparing an application for Windows and Mac using QtCreator. I want a videoplayer

Strings, write a c program to find input string using strlen(), strcpy(), s...

write a c program to find input string using strlen(), strcpy(), strcat(),strncat(), strcmp().

Super ASCII String Cost, A string S is said to be "Super ASCII", if it cont...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

#padovan string in c , #padovan string in java   program in java /...

#padovan string in java   program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : package test.padovanstring; public class PadovanStrin

3/15/2013 5:55:55 AM

Let''s work an instance. Imagine you need your constructor Foo::Foo(char) to call another constructor of the similar class, namely Foo::Foo(char,int), in order that Foo::Foo(char,int) would help initialize this object. Unluckily there''s no way to do this in C++.

Some of people do it anyway. Unluckily it doesn''t do what they want. For instance, the line Foo(x, 0); does not call Foo::Foo(char,int) on the this object. Rather then it calls Foo::Foo(char,int) to initialize temporary, local object (not this), then it instantly destructs that temporary while control flows over the ;.

class Foo { public: Foo(char x);

Foo(char x, int y);

...

};

 

Foo::Foo(char x)

{

...

Foo(x, 0); // this line does NOT help initialize the this object!!

...

}

You can combine sometimes two constructors through a default parameter:

class Foo {

public:

Foo(char x, int y=0); // this line combines the two constructors

...

};

If that doesn''t work, for example if there isn''t an suitable default parameter which combines the two constructors, every so often you can share their common code in a private init() member function:

class Foo { public: Foo(char x);

Foo(char x, int y);

... private:

void init(char x, int y);

};

 

Foo::Foo(char x)

{

init(x, int(x) + 7);

...

}

Foo::Foo(char x, int y)

{

init(x, y);

...

}

void Foo::init(char x, int y)

{

...

}

BTW do NOT attempt to get this via placement new. Some of the people think they can say new(this) Foo(x, int(x)+7) in the body of Foo::Foo(char). Constructors do a bunch of little magical things behind the scenes, but that bad technique steps on those partly constructed bits.

 

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