473,378 Members | 1,110 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,378 software developers and data experts.

Sequence of same rank constructor call

In the code below, at instantiation of a "listC" object, the
constructors for attributes "a", "b", and "c" are called in sequence
from "a" to "c".
How much is this behaviour reliable?
Does the c++ specifics tell something about it?
What are the odds for the constructors to be called in a different
sequence, like "cba" or "bca" or whatever?
What if "a", "b" and "c" are not of the same class?

Thanks,
Francesco

#include <iostream>

class itemC { public:
int item;
itemC() { std::cout << "init object at " << (void*)this <<
std::endl; }
};

class listC { public:
itemC a;
itemC b;
itemC c;
};

int main()
{
listC list;
}

//EOF

Aug 15 '06 #1
2 1289
francesco.orsen...@gmail.com wrote:
In the code below, at instantiation of a "listC" object, the
constructors for attributes "a", "b", and "c" are called in sequence
from "a" to "c".
How much is this behaviour reliable?
Does the c++ specifics tell something about it?
What are the odds for the constructors to be called in a different
sequence, like "cba" or "bca" or whatever?
What if "a", "b" and "c" are not of the same class?

Thanks,
Francesco

#include <iostream>

class itemC { public:
int item;
itemC() { std::cout << "init object at " << (void*)this <<
std::endl; }
};

class listC { public:
itemC a;
itemC b;
itemC c;
};

int main()
{
listC list;
}

//EOF
The constructors are guaranteed to be called in the order of member
declaration. Even if you put their constructors in a different order in
your initialization list, they will still be called in the order of
member declaration.

Cheers! --M

Aug 15 '06 #2

Wow, that was fast!
Thanks man, this saves me a lot of troubles!!!!

Cheers,
Francesco
The constructors are guaranteed to be called in the order of member
declaration. Even if you put their constructors in a different order in
your initialization list, they will still be called in the order of
member declaration.

Cheers! --M
Aug 15 '06 #3

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

Similar topics

2
by: Honne Gowda A | last post by:
Hi, Can anybody clarify why destruction happens in reverse way? for example A<-B<-C, when C's object is constructed, ctor calls will A(),B() and C(), when this object is destroyed, sequence of...
0
by: Miquel | last post by:
Hi all. I felt frustrated when developing an 'UserControl' derivated from textBox, because sequence event (and Validate event) seems to fail. I Always thought my code was wrong. But after...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
14
by: pat270881 | last post by:
hello, I have to implement a sequence class, however the header file is predefined class sequence { public: // TYPEDEFS and MEMBER CONSTANTS
1
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
1
by: VanKha | last post by:
Please explain for me the array-based sequence ! My textbook says that " position store element and rank , and sequence is an array store positions(in this array implementation".So why store the rank...
3
by: Rudi | last post by:
Hello, following problem: At program end or release an assembly a serial device should get a final exit sequence. How can I do this? With Dispose() it's no problem, but this assembly is used...
6
by: Christof Warlich | last post by:
Hi, the few lines of code below show different results depending on the compiler version (gcc-2.95 versus gcc-3.3 and later): gcc-2.95 first initializes d (line 9) and then t (line 8), as...
21
by: bilgekhan | last post by:
After doing a succcessful insert() or find() on a set<Tcontainer is it possible to get the item number of this item in the set? (ie. its zero-based sequence number (position/location/rank/index)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.