I'm trying to make a constructor in C++ (C++17 is fine), which has one argument, and I want this argument to be inherited from two types.
So I have this struct:
struct SceneNodeData {
Drawable* drawable;
Transformable* transformable;
SceneNodeData(
Drawable* drawable,
Transformable* transformable
) : drawable(drawable), transformable(transformable) {}
};
But for convenience I want another constructor, with only one parameter, which is Drawable and Transformable at the same time (like Sprite):
struct SceneNodeData {
Drawable* drawable;
Transformable* transformable;
SceneNodeData(
<Drawable, Transformable>* drawableAndTransformable
) : drawable(drawableAndTransformable), transformable(drawableAndTransformable) {}
};
Is there any way to do this in C++ ?
std::enable_ifandstd::is_base_of.class Sprite : public Drawable, public Transformableorclass Text : public Drawable, public Transformable(but it can be anything which is derived from Drawable and Transformable)