473,513 Members | 3,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

understanding flow between object creation and member initialization list

sks
hi ,
i Have a code snippet as follows
class ABC
{
int &r;
ABC(int a=0): r(a) {}
};

int main()
{
ABC obj;
return 0;
}

We all know that object is created then constructor is called . my
question is what is the status of object when member initialization
list is called .

Jul 6 '06 #1
4 1546

"sks" wrote:
class ABC
{
int &r;
ABC(int a=0): r(a) {}
};

int main()
{
ABC obj;
return 0;
}

We all know that object is created then constructor is called . my
question is what is the status of object when member initialization
list is called .
The member list initialisation happens before
constructor body is entered.

The members in the list are initialised in the same
order as they are declared in class body,
NOT in the order they were put in the initialisation list.

/Pavel
Jul 6 '06 #2
* sks:
hi ,
i Have a code snippet as follows
class ABC
{
int &r;
ABC(int a=0): r(a) {}
Undefined behavior.
};

int main()
{
ABC obj;
return 0;
}

We all know that object is created then constructor is called .
An object of class T is considered to have been created (to exist) when
the class T constructor has finished execution successfully.

my question is what is the status of object when member initialization
list is called .
The initialization list is not "called" in any sensible meaning of the
word, it's executed.

Before that memory has been allocated for the object, but this memory is
uninitialized.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 6 '06 #3
sks

Alf P. Steinbach wrote:
* sks:
hi ,
i Have a code snippet as follows
class ABC
{
int &r;
ABC(int a=0): r(a) {}

Undefined behavior.
};

int main()
{
ABC obj;
return 0;
}

We all know that object is created then constructor is called .

An object of class T is considered to have been created (to exist) when
the class T constructor has finished execution successfully.

my question is what is the status of object when member initialization
list is called .

The initialization list is not "called" in any sensible meaning of the
word, it's executed.

Before that memory has been allocated for the object, but this memory is
uninitialized.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
if the object is not created then why does the control go to the
initialization list

Jul 6 '06 #4
* sks:
[quoting signature]
Please don't quote signatures. Please read the FAQ before posting. Thanks.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

106
5472
by: A | last post by:
Hi, I have always been taught to use an inialization list for initialising data members of a class. I realize that initialsizing primitives and pointers use an inialization list is exactly the same as an assignment, but for class types it has a different effect - it calls the copy constructor. My question is when to not use an...
2
1823
by: Mike | last post by:
Hey guys, need some help understanding some things that maybe someone can explain or clarify it a little better then a text book. Here is my understanding so far: Class - basically a shell for your code Fields - basically just a variable but can be "write protected" Properties - access fields, they can retrieve data contained in the...
10
3503
by: Fred Ma | last post by:
Are there any reasons that would make it bad for C++ to allow simultaneous declaration and initilization of member data? Current way: ------------ class DerivedClass : BaseClass { { enum { lengthSV=16 }; // Length of SomeVector vector<double> SomeVector;
2
2964
by: Ryan Mitchley | last post by:
Hi all I have code for an object factory, heavily based on an article by Jim Hyslop (although I've made minor modifications). The factory was working fine using g++, but since switching to the Intel compiler it has stopped working. I think the singleton pattern static instance thing may be at the root of the problem, but I'm not sure. I had...
11
3798
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of...
11
2399
by: asdf | last post by:
The oder of member initialization is the order in which the members are defined. So the following code is problematic: class X{ int i; int j; public: X(int val):j(val),i(j){}
5
2658
by: Bryan | last post by:
Hi, Where is the proper place to use a member initialization list, the header or cpp file? Does it make any difference? Also, is there any difference between using a member initialization list and initializaing member variables in the constructor?
13
5364
by: JohnQ | last post by:
Why would anyone write: class SomeThing // class littered with non-domain single-instancing code :( { private: SomeThing(); static SomeThing* pInstance_; public: static SomeThing* getInstance()
7
1761
by: v4vijayakumar | last post by:
Is it possible to implement member object's virtual functions, in the containing class? If not, is it possible to simulate this behavior? ex: class test { protected: virtual void fun() = 0; };
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7125
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4757
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.