Constructor questions

Discussion in 'C++' started by Tim Frink, Jun 28, 2008.

  1. Tim Frink

    Tim Frink Guest

    Hi,

    I've two questions on constructors:

    1) Is the order in which class member are initialized
    within the constructor crucial? So, do I have to preserve
    the order in which class member have been declared in the header
    file also for the constructor initializations?

    2) Must STL containers like "list<ClassA*> mList" which I
    declare in the header file be also initialized in the
    constructor?

    Regards,
    Tim
     
    Tim Frink, Jun 28, 2008
    #1
    1. Advertising

  2. Tim Frink

    peter koch Guest

    On 28 Jun., 13:27, Tim Frink <> wrote:
    > Hi,
    >
    > I've two questions on constructors:
    >
    > 1) Is the order in which class member are initialized
    > within the constructor crucial? So, do I have to preserve
    > the order in which class member have been declared in the header
    > file also for the constructor initializations?


    The order of initialisation will be in order of declaration (with base-
    classes initialised first from left to right unless the base-class is
    virtual). The order is therefore determined by the declaration and
    good code would always follow that order.
    >
    > 2) Must STL containers like "list<ClassA*> mList" which I
    > declare in the header file be also initialized in the
    > constructor?


    Yes, but it always will be. If you say nothing explicitly about mList
    in the initialiser list, mLists default constructor will be called
    (creating an empty list), just as for any other member or base-class.

    /Peter
     
    peter koch, Jun 28, 2008
    #2
    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. Giulio
    Replies:
    9
    Views:
    1,046
    Patrick Kowalzick
    Jun 25, 2003
  2. Brett Irving
    Replies:
    3
    Views:
    3,337
    John Harrison
    Jun 29, 2003
  3. lallous
    Replies:
    5
    Views:
    8,823
    David Harmon
    Jan 23, 2004
  4. Aire
    Replies:
    3
    Views:
    468
    Mike Wahler
    Jan 25, 2004
  5. Generic Usenet Account
    Replies:
    10
    Views:
    2,245
Loading...

Share This Page