understanding flow between object creation and member initialization list

S

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 .
 
P

Pavel Vozenilek

sks said:
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
 
A

Alf P. Steinbach

* 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.
 
S

sks

Alf said:
* sks:

Undefined behavior.


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



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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top