I have an abstract base class that needs some objects passed to its constructor to initialize its members. But I would like to get rid of passing those objects through the derived class constructor.
class Derived : public Base
{
public:
Derived(type one, type two, type three) : Base(one, two, three)
{
// ...
The objects passed to the base classes are the same instances for all created derived classes. Is there a way to bind them to the base class' constructor, so that I don't have to forward them through the derived class' constructor?
// do some magic
// ...
class Derived : public Base
{
// no need for an explicit constructor anymore
// ...
In C++11 you can inherit constructors to the base class. It seems this would roughly do what you need:
class derived
: public base {
public:
using base::base;
// ...
};