home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!atto.cs.umn.edu!hansen
- From: hansen@atto.cs.umn.edu (David M. Hansen)
- Subject: Re: Calling pure virtual functions in base class constructor
- Message-ID: <1992Nov24.010222.11316@news2.cis.umn.edu>
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Nntp-Posting-Host: atto.cs.umn.edu
- Organization: University of Minnesota
- References: <722544958snx@trmphrst.demon.co.uk>
- Date: Tue, 24 Nov 1992 01:02:22 GMT
- Lines: 36
-
- In article <722544958snx@trmphrst.demon.co.uk>, nikki@trmphrst.demon.co.uk (Nikki Locke) writes:
- |> Aha, a man who knows ! That's that one explained entirely to my
- |> satisfaction.
- |>
- |> However, what I _really_ wanted to know is why, in a constructor or
- |> destructor, you still have to specify the scope override operator to call
- |> a pure virtual.
- |>
- |> Example :
- |>
- |> class A {
- |> public:
- |> A() {
- |> pure_virtual(); // undefined behaviour - WHY ?
- |> A::pure_vurtual(); // O.K.
- |> }
- |> virtual void pure_virtual() = 0;
- |> };
- |>
- |> void A::pure_virtual()
- |> {
- |> cout << "A::pure_virtual() called\n";
- |> }
- |>
- |> What is the logical reason for this, then ?
-
- At the bottom of p. 215 of the ARM it states, "The reason this makes technical
- sense is that the explicit call A::f() avoids use of the virtual call
- mechanism (S10.2) that cannot be used for a pure virtual function from within a
- constructor. If A::f() calls a pure virtual function for its object then it
- in turn will encounter a disaster just as the constructor would have."
-
- Note that this is valid only if the pure virtual function is defined.
-
- -=Dave
-
-