multiple constructors and class reference variables

N

Neil Zanella

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top