Ctor/Dtor order

Discussion in 'C++' started by Karl Heinz Buchegger, Jul 30, 2003.

  1. 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
    Karl Heinz Buchegger, Jul 30, 2003
    #1
    1. Advertising

  2. "shura" <> 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
    Victor Bazarov, Jul 30, 2003
    #2
    1. Advertising

  3. Karl Heinz Buchegger

    shura Guest

    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.
    shura, Jul 30, 2003
    #3
  4. Karl Heinz Buchegger

    Greg Comeau Guest

    In article <bg8d23$dk4$>,
    shura <> 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?
    Greg Comeau, Jul 30, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacques Labuschagne

    Explicit ctor/dtor calls

    Jacques Labuschagne, Jul 20, 2003, in forum: C++
    Replies:
    3
    Views:
    336
    Michael Kochetkov
    Jul 20, 2003
  2. pmastroianni

    Does a ctor/dtor occupy memory

    pmastroianni, Apr 1, 2005, in forum: C++
    Replies:
    1
    Views:
    340
    Howard
    Apr 1, 2005
  3. Grizlyk
    Replies:
    8
    Views:
    468
    Grizlyk
    Nov 29, 2006
  4. Replies:
    5
    Views:
    382
    Kai-Uwe Bux
    Nov 29, 2006
  5. , India
    Replies:
    2
    Views:
    308
    Stefan Ram
    Mar 30, 2010
Loading...

Share This Page