In the Stroustrup C ++ programming language (4th ed.), Section 27.4.2 shows a method for โlinearizingโ the diamond class hierarchy to avoid the overhead of virtual base classes. He starts with a diamond drawing from a real project ( Bar Code Analysis Tool ):

The linear version is drawn as:

and

Code Scheme:
namespace ipr { struct Node { ... }; struct Expr : Node { ... }; struct Stmt : Expr { ... }; struct Decl : Stmt { ... }; struct Var : Decl { ... }; namespace impl { template<class T> struct Node : T { ... }; template<class T> struct Expr : Node<T> { ... }; template<class S> struct Stmt : S { ... }; template<class D> struct Decl : Stmt<Expr<D>> { ... }; struct Var : Decl<ipr::Var> { ... }; } }
The irregular structure confuses me. Based on the original description, I expected impl to look something like this:
namespace impl { template<class T> struct Node : T { ... }; template<class T> struct Expr : Node<T> { ... }; template<class S> struct Stmt : Expr<S> { ... }; template<class D> struct Decl : Stmt<D> { ... }; struct Var : Decl<ipr::Var> { ... }; }
And I think the complete diagram of these classes is:

My question is , why don't the "internal" three impl template templates have parallel forms, as in my version of the code?
source share