Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I recently stumbled over the following C++ Code which confused me a bit: class O

ID: 658608 • Letter: I

Question

I recently stumbled over the following C++ Code which confused me a bit:

class One {/*definition*/};
template<class Base > class Two : public Base {/*definition*/};
template<class Base > class Three : public Base {/*definition*/};
template<class Base > class Four : public Base {/*definition*/};
class Five : public Four < Three< Two < One > > > {/*definition*/};
I know the purpose of templates and more or less when and how to use them.

Is there a name or a common pattern for a cascade of several templates?

When would I use this pattern (instead of anything less complex)?

P.S.: definition of class Five actually is empty.

Explanation / Answer

At a guess I'd say that the author was implementing a form of mixin.

The class with the object's primary functionality would be One, but Two, Three etc are adding various pieces of orthogonal functionality that aren't particularly coupled to the primary class. Five is then just a placeholder for taking the aggregation.