🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by John Ellis Tue, 26 Jan 1993 04:33
Constructors and runtime typing
#1368
Author: John Ellis
Date: Tue, 26 Jan 1993 04:33
15 lines
772 bytes
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.)

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.  
Re: Constructors and runtime typing
#1373
Author: Bjarne Stroustrup
Date: Tue, 26 Jan 1993 18:38
35 lines
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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads