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

Ctor/Dtor order

P: n/a
Hi!

Situation:

class A
{
B m_B;
C m_C;
};

Can I assume that for all C++ compilers
the order of subobjects creation is:
m_B first then m_C.
and the order of destruction is
m_C first then m_B.
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


shura wrote:

Hi!

Situation:

class A
{
B m_B;
C m_C;
};

Can I assume that for all C++ compilers
the order of subobjects creation is:
m_B first then m_C.
and the order of destruction is
m_C first then m_B.


yes. Thats how it is defined to be.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #2

P: n/a
"shura" <re***************@paragon.ru> wrote...
Situation:

class A
{
B m_B;
C m_C;
};

Can I assume that for all C++ compilers
the order of subobjects creation is:
m_B first then m_C.
and the order of destruction is
m_C first then m_B.


I don't think it's good to _assume_, but the order
you describe is required by the Standard. So, all
Standard-compliant compilers should do it that way.

Victor
Jul 19 '05 #3

P: n/a
In article <bg**********@newsreader.mailgate.org>,
shura <re***************@paragon.ru> wrote:
Situation:

class A
{
B m_B;
C m_C;
};

Can I assume that for all C++ compilers
the order of subobjects creation is:
m_B first then m_C.
and the order of destruction is
m_C first then m_B.


Yes. Of course, B may have its own subobjects and so on.
--
Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.