1
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'"

luis
  • 2,067
  • 2
  • 13
  • 21

1 Answers1

3

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
};
songyuanyao
  • 169,198
  • 16
  • 310
  • 405