home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11631 < prev    next >
Encoding:
Internet Message Format  |  1992-07-27  |  2.5 KB

  1. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!mips!pacbell.com!UB.com!igor!thor!rmartin
  2. From: rmartin@thor.Rational.COM (Bob Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Novice? question: Designing for mul
  5. Message-ID: <rmartin.712269742@thor>
  6. Date: 27 Jul 92 20:42:22 GMT
  7. References: <1992Jul9.144630.10863@clpd.kodak> <1992Jul17.161720.28511@ucc.su.oz>
  8. Sender: news@Rational.COM
  9. Lines: 57
  10.  
  11. maxtal@extro.ucc.su.OZ.AU writes:
  12.  
  13. >In article <rmartin.711298357@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
  14. >>maxtal@extro.ucc.su.OZ.AU (John (MAX) Skaller) writes:
  15.  
  16. |>|#define KLUDGE
  17. |>|#ifndef KLUDGE
  18. |>|class V {public: virtual void f()=0; virtual void g()=0;};
  19. |>|#else
  20. |>|class V {public: virtual void f(){printf("ERROR V::g\n");} 
  21. |>|    virtual void g(){printf("ERROR V::g\n");}};
  22. |>|#endif
  23. |>|class A1 : public virtual V {public: void f(){printf("A1::f\n");}};
  24. |>|class A2 : public virtual V {public: void g(){printf("A2::g\n");}};
  25. |>|class D : public A1, public A2 {};
  26. |>|int main()
  27. |>|{
  28. |>|    D* d=new D;
  29. |>|    A1 * a1=d;
  30. |>|    A2 * a2=d;
  31. |>|    V * v = d;
  32. |>|    d->f(); a1->f(); a2->f(); v->f();
  33. |>|    d->g(); a1->g(); a2->g(); v->g();
  34. |>|}
  35. |>
  36. |>Yes, this is a problem.  There are ambiguities which are difficult to
  37. |>resolve when trying to fit a jigsaw set of methods together through
  38. |>MI.  Should pure virtual functions be preferentially overridden by
  39. |>implemented virtual function muliply inherited from a sibling?  I am
  40. |>sure that a counter example could be conceived.
  41.  
  42. |    I am sorry, but you are quite wrong. There is NO PROBLEM with
  43. |overriding virtual functions. There is NO AMBIGUITY in the choice
  44. |of the correct function here: read ARM.
  45.  
  46. ARM 10.3 "Pure virtual functions are inherited as pur virtual functions."
  47.  
  48. Your A2 has inherited pure virtual f.  So, should D inherit it too?
  49. Or should it preferentialy choose the function defined in A1.  The ARM
  50. seems to indicate in 10.10c that A1::f will be used by D, but 10.3
  51. also seems to state that D::f will be pure virtual.  This is an
  52. ambiguity.
  53.  
  54. |    The fact that it works when KLUDGE is defined PROVES that.
  55.  
  56. By setting KLUDGE, you take 10.3 out of the picture, and the ambiguity
  57. is resolved.  
  58.  
  59. Should 10.3 hold sway in the presence of 10.10.c?  Good question.  I
  60. can see arguments supporting both sides. 
  61.  
  62.  
  63. --
  64. +---Robert C. Martin---+-RRR---CCC-M-----M-| R.C.M. Consulting         |
  65. | rmartin@rational.com |-R--R-C----M-M-M-M-| C++/C/Unix Engineering    |
  66. |     (Uncle Bob.)     |-RRR--C----M--M--M-| OOA/OOD/OOP Training      |
  67. +----------------------+-R--R--CCC-M-----M-| Product Design & Devel.   |
  68.