home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!paladin.american.edu!darwin.sura.net!mips!pacbell.com!UB.com!igor!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: Novice? question: Designing for mul
- Message-ID: <rmartin.712269742@thor>
- Date: 27 Jul 92 20:42:22 GMT
- References: <1992Jul9.144630.10863@clpd.kodak> <1992Jul17.161720.28511@ucc.su.oz>
- Sender: news@Rational.COM
- Lines: 57
-
- maxtal@extro.ucc.su.OZ.AU writes:
-
- >In article <rmartin.711298357@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
- >>maxtal@extro.ucc.su.OZ.AU (John (MAX) Skaller) writes:
-
- |>|#define KLUDGE
- |>|#ifndef KLUDGE
- |>|class V {public: virtual void f()=0; virtual void g()=0;};
- |>|#else
- |>|class V {public: virtual void f(){printf("ERROR V::g\n");}
- |>| virtual void g(){printf("ERROR V::g\n");}};
- |>|#endif
- |>|class A1 : public virtual V {public: void f(){printf("A1::f\n");}};
- |>|class A2 : public virtual V {public: void g(){printf("A2::g\n");}};
- |>|class D : public A1, public A2 {};
- |>|int main()
- |>|{
- |>| D* d=new D;
- |>| A1 * a1=d;
- |>| A2 * a2=d;
- |>| V * v = d;
- |>| d->f(); a1->f(); a2->f(); v->f();
- |>| d->g(); a1->g(); a2->g(); v->g();
- |>|}
- |>
- |>Yes, this is a problem. There are ambiguities which are difficult to
- |>resolve when trying to fit a jigsaw set of methods together through
- |>MI. Should pure virtual functions be preferentially overridden by
- |>implemented virtual function muliply inherited from a sibling? I am
- |>sure that a counter example could be conceived.
-
- | I am sorry, but you are quite wrong. There is NO PROBLEM with
- |overriding virtual functions. There is NO AMBIGUITY in the choice
- |of the correct function here: read ARM.
-
- ARM 10.3 "Pure virtual functions are inherited as pur virtual functions."
-
- Your A2 has inherited pure virtual f. So, should D inherit it too?
- Or should it preferentialy choose the function defined in A1. The ARM
- seems to indicate in 10.10c that A1::f will be used by D, but 10.3
- also seems to state that D::f will be pure virtual. This is an
- ambiguity.
-
- | The fact that it works when KLUDGE is defined PROVES that.
-
- By setting KLUDGE, you take 10.3 out of the picture, and the ambiguity
- is resolved.
-
- Should 10.3 hold sway in the presence of 10.10.c? Good question. I
- can see arguments supporting both sides.
-
-
- --
- +---Robert C. Martin---+-RRR---CCC-M-----M-| R.C.M. Consulting |
- | rmartin@rational.com |-R--R-C----M-M-M-M-| C++/C/Unix Engineering |
- | (Uncle Bob.) |-RRR--C----M--M--M-| OOA/OOD/OOP Training |
- +----------------------+-R--R--CCC-M-----M-| Product Design & Devel. |
-