Article View: comp.std.c++
Article #1373Re: Constructors and runtime typing
From: Bjarne Stroustrup
Date: Tue, 26 Jan 1993 18:38
Date: Tue, 26 Jan 1993 18:38
35 lines
1532 bytes
1532 bytes
ellis@parc.xerox.com (John Ellis @ Xerox PARC) writes
> Regarding Stroustrup's proposal for runtime typing:
>
> Suppose class B is derived from A and A's constructor calls typeof(*this):
>
> class A {A() {...typeof(*this)...}; ...};
> class B: A {...};
>
> (Excuse any mistakes in notation.)
It is typeid() not typeof().
> When "new B" is evaluated, will typeof(*this) yield typeof(A) or
> typeof(B)?
>
> The recommended implementation technique seems to suggest typeof(A),
> and that's consistent with the handling of virtual functions within
> constructors.
typeid(*this)==typeid(A)
As you point out anything else would be inconsistent with the behavior
of virtual functions.
References:
Run-Time Type Identification for \*C (Revised). Proc USENIX 1992 C++ Conference
x3j16/92-0121, WG21/N0198: Run-Time Type Identification for \*C (Revised yet again)
Both by me and Dmitry Lenkov. The latter was revised to reflect discussions at the USENIX conference and
elsewhere.
Technical Details
Message-ID:
<24711@alice.att.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!ames!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!bsReferences:
<ellis.728022822@osric>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!ames!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!bs From: bs@alice.att.com (Bjarne Stroustrup) Newsgroups: comp.std.c++ Subject: Re: Constructors and runtime typing Message-ID: <24711@alice.att.com> Date: 26 Jan 93 18:38:57 GMT Article-I.D.: alice.24711 References: <ellis.728022822@osric> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 35