Should you employ this pointer in the constructor?, C/C++ Programming

Assignment Help:

Should you employ this pointer in the constructor?


Related Discussions:- Should you employ this pointer in the constructor?

TCP, check this link: http://cactus.eas.asu.edu/partha/Teaching/430.2013/...

check this link: http://cactus.eas.asu.edu/partha/Teaching/430.2013/Project/proj-2.2013.htm

Prime no., program to find if a no . is prime or not

program to find if a no . is prime or not

Define polymorphism?, Define Polymorphism? A: Polymorphism let a client ...

Define Polymorphism? A: Polymorphism let a client to treat distinct objects in the similar way even if they were developed from distinct classes and exhibit different behaviors.

Nested if else, input marks of c and c++ if c grater than equal to 50 grate...

input marks of c and c++ if c grater than equal to 50 grater than 50 you are pass if c greater than equal to 50 c++ less than 50 than supplementry c++ if c less then 50 and c++ gra

Determine the canonical form, Rule: To determine the canonical form we s...

Rule: To determine the canonical form we should OR the min terms. A min term is defined as a Boolean equation of the input if the output is logic '1'. If the input is logic '1'

Simplify the logical phrase with C++, hi i want wite a C++ program that get...

hi i want wite a C++ program that get one logical phrase (included {x,y,z,w,1,0}) and simplify it! but i ''m confused! thanxs for anubody help me...

What are the debugging methods you employ while came across , What are the ...

What are the debugging methods you employ while came across a problem? A: Debugging with tools such as: 1.      DBG, GDB ,Forte, Visual Studio. 2.      Using tusc to trace

Program to draw a circle - c program, Program to draw a circle: int ma...

Program to draw a circle: int main(void) {    /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int midx, midy;    int radius = 100;

Define the char data type of c language, Define the Char Data Type of C Lan...

Define the Char Data Type of C Language? The char defines characters. The char type will usually require only 1 byte of internal storage. Every char type has an equivalent inte

3/15/2013 6:02:15 AM

A: Some of people feel you must not use the pointer in a constructor since the object is not fully formed yet. Though, you can use this in the constructor (in the {body} and even in the initialization list) if you are careful.

Here is something which always works: the {body} of a constructor (or a function called from the constructor) can access reliably the data members declared in a base class and/or the data members declared in the constructor''s own class. It is because all of those data members are guaranteed to have been completely constructed by the time the constructor''s {body} starts executing.

Here is something which never works: the {body} of a constructor (or a function called from the constructor) can''t get down to a derived class via calling a virtual member function i.e. overridden in the derived class. If your aim was to obtain to the overridden function in the derived class, you won''t obtain what you wish. Note down that you won''t get to the override in the derived class independent of how you call virtual member function: explicitly via the this pointer (for example this->method()), implicitly using this pointer (for example method()), or even calling some other function which calls the virtual member function onto your this object. The bottom line is this: even if the caller is building an object of a derived class, throughout the constructor of the base class, your object is not still of that derived class.

Here is something which sometimes works: if you pass any data members in this object to another data member''s initialize, you have to ensure that the other data member has already been initialized. You can determine whether the other data member has (or has not) been initialized by using some straightforward language rules which are independent of the particular compiler you''re utilizing. The bad news is that you ought to know those language rules (for example: base class sub-objects are initialized first (look up the order if you have multiple and/or virtual inheritance!), then data members described in the class are initialized in the order wherein they appear in the class declaration). If you don''t know about these rules, then don''t pass any data member from the object (regardless of whether or not you use explicitly this keyword) to any other data member''s initializer! And if you do know about the rules, be careful please.

 

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