C++ Logo

std-discussion

Advanced search

Re: inheriting initializer_list constructor fails with empty list

From: M.P. <dbc_at_[hidden]>
Date: Tue, 28 May 2024 13:58:57 -0000
> B doesn't have a default constructor, just like A doesn't have one

B has an implicitly-declared default constructor, see
[class.default.ctor]/1.

Adding a user-declared constructor to B suppresses the implicit
declaration:

 #include <initializer_list>

 struct A { A(std::initializer_list<int>); };
 struct B : A {
  using A::A;
  B(void*);
 };

 A a {}; // ok
 B b {}; // ok

Received on 2024-05-28 13:59:10