473,224 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

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 1528

"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
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...
2
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...
10
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 {...
2
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...
11
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...
11
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
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...
13
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*...
7
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;...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...

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.