468,456 Members | 1,581 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,456 developers. It's quick & easy.

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 1342

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

106 posts views Thread by A | last post: by
2 posts views Thread by Ryan Mitchley | last post: by
11 posts views Thread by asdf | last post: by
5 posts views Thread by Bryan | last post: by
13 posts views Thread by JohnQ | last post: by
7 posts views Thread by v4vijayakumar | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.