I have created a class Patient
and I want to populate a list of Patients
with objects which I have created via the explicit constrctor. However I get a
The list's initializer takes a sequence of expressions, but you've given it full variable declarations instead. That's simply not valid syntax. You can only put declarations in "free space" in a function or at namespace scope, not inside another statement (we'll ignore the joys of conditionals for the purpose of this answer).
You probably intended to create some temporaries instead:
list<Patient> sp = {
Patient("I.Petrov", "21.12.02", 4),
Patient("D.Stoyanov", "12.02.97", 7),
Patient("K.Dimitrov", "07.08.90", 1)
};
But I'd write it as:
std::list<Patient> sp{
{"I.Petrov", "21.12.02", 4},
{"D.Stoyanov", "12.02.97", 7},
{"K.Dimitrov", "07.08.90", 1}
};