By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,232 Members | 1,641 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,232 IT Pros & Developers. It's quick & easy.

understanding flow between object creation and member initialization list

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a

"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

P: n/a
* 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

P: n/a
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

P: n/a
* 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 discussion thread is closed

Replies have been disabled for this discussion.