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