home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / cplus / 2128 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.5 KB

  1. Path: 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
  2. From: bs@alice.att.com (Bjarne Stroustrup)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Constructors and runtime typing
  5. Message-ID: <24711@alice.att.com>
  6. Date: 26 Jan 93 18:38:57 GMT
  7. Article-I.D.: alice.24711
  8. References: <ellis.728022822@osric>
  9. Organization: AT&T Bell Laboratories, Murray Hill NJ
  10. Lines: 35
  11.  
  12.  
  13.  
  14. ellis@parc.xerox.com (John Ellis @ Xerox PARC) writes
  15.  
  16.  > Regarding Stroustrup's proposal for runtime typing:
  17.  > 
  18.  > Suppose class B is derived from A and A's constructor calls typeof(*this):
  19.  > 
  20.  >     class A    {A() {...typeof(*this)...}; ...};
  21.  >     class B: A {...};
  22.  > 
  23.  > (Excuse any mistakes in notation.)
  24.  
  25. It is typeid() not typeof().
  26.  
  27.  > When "new B" is evaluated, will typeof(*this) yield typeof(A) or
  28.  > typeof(B)? 
  29.  > 
  30.  > The recommended implementation technique seems to suggest typeof(A),
  31.  > and that's consistent with the handling of virtual functions within
  32.  > constructors.  
  33.  
  34. typeid(*this)==typeid(A)
  35.  
  36. As you point out anything else would be inconsistent with the behavior
  37. of virtual functions.
  38.  
  39. References: 
  40.  
  41.     Run-Time Type Identification for \*C (Revised). Proc USENIX 1992 C++ Conference
  42.  
  43.     x3j16/92-0121, WG21/N0198: Run-Time Type Identification for \*C (Revised yet again)
  44.  
  45. Both by me and Dmitry Lenkov. The latter was revised to reflect discussions at the USENIX conference and
  46. elsewhere.
  47.