Consider the following code:
struct base
{
int x, y, z;
};
struct derived : private base
{
using base::base;
};
int main(int argc, const char *argv[])
{
base b{1, 2, 3}; // Allowed
derived d{1, 2, 3}; // Not allowed
}
The line derived d{1, 2, 3}; makes my compiler (Clang 3.3) fail with error "no matching constructor for initialization of 'derived'". Why is this? Is there any way to initialize derived via aggregate initialization?
derivedhas a base class, so it's not an aggregate (§8.5.1/1: "An aggregate is an array or a class (Clause 9) with [...] no base classes [...]").Since it's not an aggregate, it can't be initialized with aggregate initialization.
The most obvious workaround would probably be to add a
ctorto base, and have the ctor forderivedpass arguments through tobase:Of course, that doesn't work if you're set on
baseremaining an aggregate.Edit: For the edited question, I don't see a way to use an
std::initializer_listhere --std::arraydoesn't have anything to accept aninitializer_list.