Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > multiple constructors and class reference variables

Reply
Thread Tools

multiple constructors and class reference variables

 
 
Neil Zanella
Guest
Posts: n/a
 
      04-01-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is the possible to have all the public constructors of the publicbase class as the constructors of a derived class? Peng Yu C++ 5 09-19-2008 10:19 AM
Copy constructors, de/constructors and reference counts Jeremy Smith C++ 2 08-02-2006 11:25 PM
multiple constructors and class reference variables Neil Zanella C++ 2 04-01-2004 04:24 PM
multiple constructors and class reference variables Neil Zanella C++ 0 04-01-2004 09:01 AM
Constructors that call other Constructors Dave Rudolf C++ 12 02-06-2004 03:26 PM



Advertisments