chiark / gitweb /
doc/: Some minor tweaks and corrections.
[sod] / doc / intro.tex
index f4b3168d1e5f59a01120d8cffe254741a0545c28..67a220f5993e05a528228cc8661da4654e3b0248 100644 (file)
@@ -88,7 +88,7 @@ are subclasses; \Cplusplus\ has no such root class.
 Both systems provide multiple inheritance, but go about it very differently.
 The most important difference is that \Cplusplus\ provides only \emph{static
   delegation}: if you have a class @|B| which defines some (virtual) member
-function @|f|, and a derived class of @|D| which wants to \emph{extend} the
+function @|f|, and a derived class @|D| which wants to \emph{extend} the
 behaviour of @|f| on instances of @|D|, then you must explicitly call @|B::f|
 at the appropriate point:
 \begin{prog}
@@ -143,10 +143,13 @@ which is unlikely to be what was wanted: `B' prints twice, and the `before'
 and `after' actions are both in the middle.\footnote{%
   Of course, one could have arranged to call @|Y::f| before @|X::f| -- but
   the important point is that one would have needed to \emph{know} that this
-  was necessary.} %
+  was necessary.  And you still end up with two copies of `B'.} %
 The problem is that correctly composing behaviour from a collection of
 superclasses requires knowledge of all of the superclasses involved and how
-they're supposed to work together.
+they're supposed to work together.  Messing with virtual base classes has
+eliminated the problem of duplicating @|B|'s state, but has done nothing to
+help avoid duplicating @|B|'s \emph{behaviour} -- which is a shame, because
+duplicating one without the other is going to end badly.
 
 The obvious workaround is to separate the functionality -- here, printing the
 messages -- from the plumbing, which arranges to do everything in the right
@@ -161,7 +164,7 @@ the various @|_f| functions in the right order, like this:
     void _f() \{ std::cout <{}< "B@\\n"; \}                   \-\\
   public:                                                       \\ \ind
     virtual void f() \{ _f(); \}                                \\
-    virtual ~B() \{ \}                                        \-\\
+    virtual @~B() \{ \}                                        \-\\
   \};                                                           \\+
                                                                 %
   class X: virtual public B \{                                  \\