0

I want to make a simple wrapper B around a complex class A. A has many different constructors. The class B does not have any constructors, so how can I automatically pass the constructor arguments to the base class A, without needing to implement them all in B?

Here is a simple example of what I want to do:

class A
{
public:
   A(int a);
   A(const& A);
   // etc ...
};

class B : public A
{
   int b;
};

void main()
{
   B b(0);  // Since B does not have a constructor, I want it to dispatch to A::A(int)
}

note: A is a class from some package so I can not simply add my int b to A.

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83

1 Answers1

1

In B, you can inherit A's constructors:

class B : public A
{
    using A::A;
    int b;
};

Then B b(0); will work.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207