multiple constructors and class reference variables

Discussion in 'C++' started by Neil Zanella, Apr 1, 2004.

  1. Neil Zanella

    Neil Zanella Guest

    Hello,

    AFAIK the only way to initialize a reference variable defined inside a class
    is to initialize it in an initializer list. However, when there are multiple
    constructors, this means that the initializer lists have to be cut and pasted
    from one constructor to another. This does not seem to lend itself particularly
    well to maintainablility. Calling a constructor from another in C++ is not legal
    unlike in Java. Also, functions other than constructors cannot have initializer
    lists. So, if there are multiple constructors, it seems to me that the references
    need be copied and constructed the same in each initializer list. This seems
    somewhat tedious. Of course, one could always use the preprocessor and
    declare the list of common reference initializers in a macro and
    then paste the macro instead. I don't regard this particuar
    style very good either.

    Comments welcome,

    Regards,

    Neil
    Neil Zanella, Apr 1, 2004
    #1
    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. Dave Rudolf
    Replies:
    12
    Views:
    8,258
    Martijn Lievaart
    Feb 6, 2004
  2. Neil Zanella
    Replies:
    2
    Views:
    2,989
    Nick Hounsome
    Apr 1, 2004
  3. Neil Zanella
    Replies:
    0
    Views:
    250
    Neil Zanella
    Apr 1, 2004
  4. Jeremy Smith
    Replies:
    2
    Views:
    575
    Jeremy Smith
    Aug 3, 2006
  5. Peng Yu
    Replies:
    5
    Views:
    385
    Juha Nieminen
    Sep 19, 2008
Loading...

Share This Page