class A {
public:
int _a
A(int a) : _a { a} { }
};
class B : public A { }
Why can't I initialize a variable of A type with using the inherited constructor?
B a(5);
Error: "No matching constructor for initialization of 'B'"
class A {
public:
int _a
A(int a) : _a { a} { }
};
class B : public A { }
Why can't I initialize a variable of A type with using the inherited constructor?
B a(5);
Error: "No matching constructor for initialization of 'B'"
Because B
doesn't have such a constructor taking int
by default, unless inherit it explicitly:
class B : public A {
using A::A; // inheriting constructor
};