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

  1. Path: sparky!uunet!cimshop!davidm
  2. From: davidm@consilium.com (David S. Masterson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Virtual function call within constructors
  5. Message-ID: <DAVIDM.93Jan24145757@consilium.com>
  6. Date: 24 Jan 93 22:57:57 GMT
  7. References: <1993Jan24.051330.3721@dcc.uchile.cl>
  8. Sender: root@cimshop.UUCP
  9. Organization: Consilium Inc., Mountain View, California
  10. Lines: 29
  11. In-reply-to: gschwarz@dcc.uchile.cl's message of 24 Jan 93 05:13:30 GMT
  12. X-Posting-Software: GNUS 3.13  [ NNTP-based News Reader for GNU Emacs ]
  13.  
  14. >>>>> On 24 Jan 93 05:13:30 GMT, gschwarz@dcc.uchile.cl (Guillermo Schwarz
  15. >>>>> Utrup) said:
  16.  
  17. > I have found that virtual functions are not handled as one could expect
  18. > when called from a constructor.
  19.  
  20. Actually, it works exactly as expected according to the definition of C++.
  21. You must realize that the parts of a class are not really available for use
  22. until the constructor of that class has been called.  Therefore, if you have a
  23. class definition like:
  24.  
  25.     A -> B -> C
  26.  
  27. then you know that, when constructing C, A and B must first be constructed.
  28. Except for virtual functions, there is no way that A or B will try to make use
  29. of some part of C.  When a virtual function is called, then the most derived
  30. version of that virtual function that is currently available will be called.
  31. The thing to realize is that while the A part of C is being constructed, then
  32. the B and C parts of it are not yet available.
  33. --
  34. ====================================================================
  35. David Masterson                    Consilium, Inc.
  36. (415) 691-6311                    640 Clyde Ct.
  37. davidm@consilium.com                Mtn. View, CA  94043
  38. ====================================================================
  39. I'm opposed to these unsupervised weekend furloughs for first-degree
  40. murderers.
  41.                 -- George Bush, asked whether the Pledge of Allegiance
  42.                    would be his only campaign issue in 1988.
  43.