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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!well!johnrp
  3. From: johnrp@well.sf.ca.us (John Panzer)
  4. Subject: Re: Overriding the order of constructors?
  5. Message-ID: <Bz8oGx.B7x@well.sf.ca.us>
  6. Keywords: constructor ordering
  7. Sender: news@well.sf.ca.us
  8. Organization: Whole Earth 'Lectronic Link
  9. References: <1992Dec13.220943.22047@jarvis.csri.toronto.edu> <robison1.724307343@husc10>
  10. Date: Mon, 14 Dec 1992 07:50:57 GMT
  11. Lines: 40
  12.  
  13. In article <robison1.724307343@husc10> robison1@husc10.harvard.edu (Keith Robison) writes:
  14. >dembo@csri.toronto.edu (Prof. Ron Dembo) writes:
  15. >
  16. >
  17. >
  18. >>What is the rational for not allowing a programmer to override the
  19. >>default calling order of constructors and initializers?  I see
  20. >>the importance of having a well defined default.  However, why
  21. >>shouldn't the ordering of the initilizers be significant?  
  22. >
  23. >
  24. >    I believe you can effectively accomplish this dangerous
  25. >goal by calling virtual functions in your constructors:
  26. >
  27. >
  28. >class A {
  29. >  A() { reroute(); do_A_ctor_stuff(); }
  30. >  virtual void reroute(); { }
  31. >}
  32. >
  33. >class B : public A {
  34. >  B() {}
  35. >  void reroute ()  { do_B_ctor_stuff(); }
  36. >}
  37. >
  38. >
  39. >This will cause B's reroute() to be executed before any 
  40. >A constructing has occurred.
  41. >
  42.  
  43. Are you certain?  I believe that A::reroute() will
  44. be called if reroute() is called from within A's
  45. constructor or destructor.  I think this is a
  46. common C++ "gotcha" - it's certainly gotten me
  47. in the past.
  48.  
  49. John Panzer
  50. johnrp@well.sf.ca.us
  51.  
  52.  
  53.