home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17904 < prev    next >
Encoding:
Text File  |  1992-12-13  |  1.2 KB  |  47 lines

  1. Path: sparky!uunet!olivea!spool.mu.edu!uwm.edu!ogicse!hsdndev!husc-news.harvard.edu!husc10!robison1
  2. From: robison1@husc10.harvard.edu (Keith Robison)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Overriding the order of constructors?
  5. Keywords: constructor ordering
  6. Message-ID: <robison1.724307343@husc10>
  7. Date: 14 Dec 92 04:29:03 GMT
  8. References: <1992Dec13.220943.22047@jarvis.csri.toronto.edu>
  9. Lines: 35
  10. Nntp-Posting-Host: husc10.harvard.edu
  11.  
  12. dembo@csri.toronto.edu (Prof. Ron Dembo) writes:
  13.  
  14.  
  15.  
  16. >What is the rational for not allowing a programmer to override the
  17. >default calling order of constructors and initializers?  I see
  18. >the importance of having a well defined default.  However, why
  19. >shouldn't the ordering of the initilizers be significant?  
  20.  
  21.  
  22.     I believe you can effectively accomplish this dangerous
  23. goal by calling virtual functions in your constructors:
  24.  
  25.  
  26. class A {
  27.   A() { reroute(); do_A_ctor_stuff(); }
  28.   virtual void reroute(); { }
  29. }
  30.  
  31. class B : public A {
  32.   B() {}
  33.   void reroute ()  { do_B_ctor_stuff(); }
  34. }
  35.  
  36.  
  37. This will cause B's reroute() to be executed before any 
  38. A constructing has occurred.
  39.  
  40.  
  41. Keith Robison
  42. Harvard University
  43. Department of Cellular & Developmental Biology
  44. Department of Genetics / HHMI
  45.  
  46. robison@biosun.harvard.edu 
  47.