There are object behaviors I need over and over again, including ownership, pipeline-like interaction, statemachine behavior etc. I thought this to be a good opportunity to try out a new design pattern called “policies” in a quite famous book about c++.
Now I have difficulties creating a class
template <
class T,
template <typename T> class pOwnership
template <typename T> class pInteraction
>
class object : public pOwnership<T>, public pInteraction<T>
{...}
which should take 2 policies dealing with ownership and interaction.
For example, pOwnership has a method
void add(T &obj)
which adds an object to the internal list
std::vector<T*>.
(using another ownership-policy, for example when I don’t need ownership, void add(T &obj) could also be undeclared, resulting in compile-time errors if using the wrong application code)
Now the type T should be the final policy host class, meaning the object class:
typedef template<object, pOwnershipRecursive, pInteractionPipeline> myObject;
Of course object is a template-type itself, resulting in compiler errors.
How can one realize a class like myObject?
You are expected to use CRTP: