In my use case I needed to initialize a class variable using an initializer list. I learnt that an aggregate class is a class that just has user defined data members in it.
The advantage of aggregate is that we can use initializer list like this
struct fileJobPair {
int file;
int job;
};
fileJobPair obj = {10, 20};
But if I add a constructor to it, the class no longer remains an aggregate
struct fileJobPair {
int file;
int job;
fileJobPair() {
file = job = 0;
}
fileJobPair(int a, int b) {
file = a;
job = b;
}
};
But I see that the initializer list advantage that we had for aggregate classes can still be used over here.
fileJobPair obj = {10, 20};
So my question is why do we even need an aggregate if the same thing can be acieved by regular class. What are the advantages and real life use case of aggregates.