Is there a way to inherit private constructors with the using statement? I tried adding a friend statement, but it did not seem to work.
struct B;
struct A
{
private:
A(int x) {}
A(int y, double z) {}
friend struct B;
};
struct B : public A
{
public:
using A::A;
//B(int x) : A(x) {}
//B(int x, int y) : A(x, y) {}
};
void demo()
{
B b1(5); // does not compile - implicit constructor is not accessible
B b2(4, 9.0);
}
I wonder if there is any way to do it with using, since if I explicitly create the delegating constructors the friend statement works, so this seams inconsistent:
struct B;
struct A
{
private:
A(int x) {}
A(int y, double z) {}
friend struct B;
};
struct B : public A
{
public:
B(int x) : A(x) {} // OK
B(int x, int y) : A(x, y) {}
};
void demo()
{
B b1(5); // OK
B b2(4, 9.0);
}