The problem is that you are using a C++ compiler that compiles your program based on the C++ Standard before the C++ 17 Standard.
Before the C++ 17 Standard aggregates may not contain base classes.
So use the compiler option that sets at least the specification of the C++ 17 Standard.
According to the C++ 14 Standard (8.5.1 Aggregates)
1 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).
Starting from the C++ 17 Standard aggregates are allowed to have base classes (11.6.1 Aggregates)
1 An aggregate is an array or a class (Clause 12) with
(1.1) — no user-provided, explicit, or inherited constructors (15.1),
(1.2) — no private or protected non-static data members (Clause 14),
(1.3) — no virtual functions (13.3), and
(1.4) — no virtual, private, or protected base classes (13.1).
Pay also attention to that there is a difference according to aggregates in the C++17 and the C++20 Standards. For example in C++ 17 you are allowed to declare a constructor for an aggregate with the specifier default
.
That is this program
struct A {
int x;
};
struct B : public A {
B() = default;
};
int main()
{
A a{ 1 };
B b{ 2 };
}
is valid according to the C++ 17 Standard and is invalid according to the C++20 Standard.
But if you will declare the constructor with the specifier explicit
struct B : public A {
explicit B() = default;
};
then the program will not be valid even according to the C++ 17 Standard.