Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Constructor question Message-ID: <72179@microsoft.UUCP> Date: 6 May 91 17:24:35 GMT References: <1991Apr2.110623.22219@and.cs.liv.ac.uk> <20164@alice.att.com> <1991Apr18.005426.21863@dragon.wpd.sgi.com> <71952@microsoft.UUCP> <1991Apr30.211213.15118@alias.com> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 24 In article <1991Apr30.211213.15118@alias.com> rae@alias.com (Reid Ellis) writes: |Jim ADCOCK writes: |>Again, if you want to factor out common code from constructors, I recommend |>you follow Bjarne's suggestion: write a private init() routine which is |>called from within each constructor. | |But this does not work for constant objects. What then? In order of increasing evilness some ideas are: 1) You can still use an init() function per const member variable using the : syntax [but this would become tedious if many members had to be initialized this way.] 2) You can put a bunch of the const member variables in a struct that can then be init'ed as a unit. 3) You can fake init() using a macro that then textually substitutes in the right : syntax. 4) You can write a "const" init() function that then casts-away constnesses. I consider #4 pretty evil -- but still a lot better than the doubled- construction hack.