W języku programowania(str. 4) Stroustrupa (czwarta edycja) sekcja 27.4.2 przedstawia technikę "linearyzacji" hierarchii klasy diamentów, aby uniknąć narzutów na wirtualne klasy bazowe. Zaczyna z wzorem diamentu z prawdziwego projektu (Pivot code analyzer tool):Wyjaśnienie hierarchii klas hierarchicznych według Stroustrupa, przykład
Wersja liniowy jest narysowany jako:
i
The Zarys kodu:
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> { ... };
}
}
Jestem zdezorientowany przez nieregularną strukturę. Na podstawie wstępnego opisu, spodziewałem impl
wyglądać mniej więcej tak:
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> { ... };
}
I myślę pełny schemat tych zajęć jest:
Moje pytanie brzmi:, dlaczego trzy klasy szablonów "wnętrza" nie mają form równoległych, tak jak w mojej wersji kodu?