X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/756e9293611d2b1dc34fba6cca89fd70098f5546..ed3ce6c2352d76442b79badfbe08bc6ecde6934d:/doc/intro.tex diff --git a/doc/intro.tex b/doc/intro.tex index f77eed0..67a220f 100644 --- a/doc/intro.tex +++ b/doc/intro.tex @@ -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 \{ \\