home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!centerline!matt
- From: matt@centerline.com (Matt Landau)
- Subject: Re: constructor call during initialization of same class
- Message-ID: <matt.714605642@centerline.com>
- Sender: news@centerline.com
- Nntp-Posting-Host: rapier
- Organization: CenterLine Software, Inc.
- References: <1992Aug23.030355.23047@athena.mit.edu> <1992Aug23.154530.1131@taumet.com>
- Date: Sun, 23 Aug 1992 21:34:02 GMT
- Lines: 25
-
- In <1992Aug23.154530.1131@taumet.com> steve@taumet.com (Steve Clamage) writes:
- >I am guessing that you want to share some code by having several
- >constructors call a "basic" constructor. You can't do that with
- >a construcutor. You can write an initialization function which all
- >constructors call.
-
- Yes, you can, but it's not quite the same semantically. In particular,
- using initalization functions means you cannot initialize data members
- that are references, and you cannot initialize data members that are
- instances of classes by using their copy constructors. (You end up
- using their assignment operators instead if assign to them in your
- shared initialization member function.)
-
- More properly, of course you CAN initialize references and perform copy
- construction of data members that are instances, but you have to do it
- by using the usual data member initialization syntax, and you have to
- do it explicitly in every overloading of the constructor. Where there
- are a large number of such data members, or when the class design is
- very fluid (early in the design, for instance), it's very easy to miss
- one or two of these.
-
- I think THAT is the problem the original poster was trying to address;
- it's a problem that being able to call alternate overloadings of your
- own constructor would address. Are there any ways to deal with it in
- the language as currently defined?
-