🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1628

Re: Why not A::A(something) : A(other) {} ?

#1628
From: Warner Losh
Date: Sun, 06 Aug 1995 22:38
53 lines
2489 bytes
In article <DCwops.HEo@world.std.com>, Tom Breton <tob@world.std.com> wrote:
>"Factoring out" is usually proposed as a work-around, but it's not
>really a solution. 0) It can't initialize reference or const members. 1)
>Conceptually, it's just wrong. A member function should do stuff after
>construction, not before construction. Construction should come from
>ctors.

While 0) is kinda true (you can initialize them before you call
construct()) 1) needn't be true.

We found, in the OI project, that often times you want to call member
functions from a constructor.  These usually set the values of
variables, and what not, but other times had side effects (and we
desired them to have side effects).  We also found that we needed to
have, for every class, two slightly different ctors (we were passing
RTTI-like pointers around before RTTI was part of the language).  We
had little to no problems initializing our classes with construct()
member function that was private.

The only snag we ever hit was that a certain compiler would issue
warnings incorrectly in the following case:

	class A {
	...
	private:
		construct( int );
	...
	};

	class B : public A {
	...
	private:
		construct( int, int );
	...
	};

it would say that B::construct(int, int) hides A::construct(int).
Since A::construct is private, it is irrelevant that B::construct
hides it.  Any objects derived from A could never access or call it,
only in A's member functions would it be accessible (and you want it
that way).  The compiler people pig-headedly wouldn't listen to us and
refused to even consider making the change, or adding some sort of
pragma that says "Damnit, we know that, don't tell us about it."

[[ The actual compiler also was buggy in when it would or wouldn't
   issue the warning, based on if the class had any virtual functions
   or not (but sometimes it would be silent, even with virtuals) ]]

Warner
-- 
Warner Losh		"VMS Forever"		home: imp@village.org
Cyberspace Development, Inc			work: imp@marketplace.com
Makers of TIA, The Internet Adapter.		http://marketplace.com/
Technical Details
Message-ID: <403g8o$r9g@rover.village.org>
Path: arc1-ca.pugleaf.net!village.org!not-for-mail
References: <3vu8ve$e6h@usenet.rpi.edu> <DCwops.HEo@world.std.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!village.org!not-for-mail
From: imp@village.org (Warner Losh)
Newsgroups: comp.std.c++
Subject: Re: Why not A::A(something) : A(other) {} ?
Date: 6 Aug 1995 16:38:16 -0600
Organization: The Village
Message-ID: <403g8o$r9g@rover.village.org>
References: <3vu8ve$e6h@usenet.rpi.edu> <DCwops.HEo@world.std.com>
NNTP-Posting-Host: rover.village.org