home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20054 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.5 KB  |  32 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!brunix!cs.brown.edu!pcm
  3. From: pcm@cs.brown.edu (Peter C. McCluskey)
  4. Subject: Re: Virtual function call within constructors
  5. Message-ID: <1993Jan28.224626.8775@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Brown Computer Science Dept.
  8. References: <1993Jan24.051330.3721@dcc.uchile.cl> <1993Jan24.164709.18400@taumet.com> <rmartin.728088421@stripe>
  9. Date: Thu, 28 Jan 1993 22:46:26 GMT
  10. Lines: 20
  11.  
  12. In article <rmartin.728088421@stripe>, rmartin@stripe.Rational.COM (Bob Martin) writes:
  13. |> >gschwarz@dcc.uchile.cl (Guillermo Schwarz Utrup) writes:
  14. |> >>I have found that virtual functions are not handled as one could expect
  15. |> >>when called from a constructor.
  16.  
  17. |> So be very careful in your constructors and destructors.  Since
  18. |> virtual functions don't deploy, they should not be called.  If calling
  19. |> them is necessary then use the scope operator to call them directly:
  20. |> (e.g. MyClass::MyVirtualFunction()).  Never call a pure virtual
  21. |> function from a constructor or a destructor.....
  22.  
  23.  I would expect that any decent compiler would give a warning when
  24. the scope operator is ommitted on a virtual function call in a constructor
  25. or destructor. However, I have tested this on 2 well-known compilers and
  26. seen no diagnostics. Would any compiler writers care to justify this
  27. apparent oversight?
  28. -- 
  29. ----------------------------------------------------------------------
  30.   >> Peter McCluskey >> pcm@cs.brown.edu >>   Reunite Gondwanaland!
  31. ----------------------------------------------------------------------
  32.