understanding flow between object creation and member initialization list

Discussion in 'C++' started by sks, Jul 6, 2006.

  1. sks

    sks Guest

    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 .
    sks, Jul 6, 2006
    #1
    1. Advertising

  2. "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
    Pavel Vozenilek, Jul 6, 2006
    #2
    1. Advertising

  3. Re: understanding flow between object creation and member initializationlist

    * 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?
    Alf P. Steinbach, Jul 6, 2006
    #3
  4. sks

    sks Guest

    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
    sks, Jul 6, 2006
    #4
  5. Re: understanding flow between object creation and member initializationlist

    * 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?
    Alf P. Steinbach, Jul 6, 2006
    #5
    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. Replies:
    3
    Views:
    828
    Peter_Julian
    Oct 10, 2005
  2. sks
    Replies:
    9
    Views:
    318
    Robbie Hatley
    Jul 14, 2006
  3. Jess
    Replies:
    23
    Views:
    908
  4. Jack Dowson
    Replies:
    0
    Views:
    445
    Jack Dowson
    May 7, 2007
  5. aaragon
    Replies:
    2
    Views:
    604
    James Kanze
    Nov 2, 2008
Loading...

Share This Page