struct A
{
int a;
int b;
void foo(){}
};
A a{1, 2};
It works fine. But if change foo to a virtual function, It will not compile with error,
Error C2440 'initializing': cannot convert from 'initializer list' to
I find this,
An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
But what's the reason behind it?
std::is_standard_layout<T>
. So maybe this wouldn't allow aggregates to work as expected. The user provided constructor is another story - to me it's about how to choose between it and an aggregate init. You can add a ctor with initializer_list – Microscopy