home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16814 < prev    next >
Encoding:
Text File  |  1992-11-24  |  1.7 KB  |  49 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!atto.cs.umn.edu!hansen
  3. From: hansen@atto.cs.umn.edu (David M. Hansen)
  4. Subject: Re: Calling pure virtual functions in base class constructor
  5. Message-ID: <1992Nov24.010222.11316@news2.cis.umn.edu>
  6. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  7. Nntp-Posting-Host: atto.cs.umn.edu
  8. Organization: University of Minnesota
  9. References:  <722544958snx@trmphrst.demon.co.uk>
  10. Date: Tue, 24 Nov 1992 01:02:22 GMT
  11. Lines: 36
  12.  
  13. In article <722544958snx@trmphrst.demon.co.uk>, nikki@trmphrst.demon.co.uk (Nikki Locke) writes:
  14. |> Aha, a man who knows ! That's that one explained entirely to my 
  15. |> satisfaction. 
  16. |> 
  17. |> However, what I _really_ wanted to know is why, in a constructor or
  18. |> destructor, you still have to specify the scope override operator to call 
  19. |> a pure virtual.
  20. |> 
  21. |> Example :
  22. |> 
  23. |> class A {
  24. |> public:
  25. |>     A() { 
  26. |>         pure_virtual();        // undefined behaviour - WHY ?
  27. |>         A::pure_vurtual();    // O.K.
  28. |>         }
  29. |>     virtual void pure_virtual() = 0;
  30. |>     };
  31. |> 
  32. |> void A::pure_virtual()
  33. |> {
  34. |>     cout << "A::pure_virtual() called\n";
  35. |> }
  36. |> 
  37. |> What is the logical reason for this, then ?
  38.  
  39. At the bottom of p. 215 of the ARM it states, "The reason this makes technical
  40. sense is that the explicit call A::f() avoids use of the virtual call 
  41. mechanism (S10.2) that cannot be used for a pure virtual function from within a 
  42. constructor.  If A::f() calls a pure virtual function for its object then it
  43. in turn will encounter a disaster just as the constructor would have."
  44.  
  45. Note that this is valid only if the pure virtual function is defined.
  46.  
  47.                     -=Dave
  48.  
  49.