I'm looking for a way to initialize only first values in std::map and then initialize the second ones according to the keys. here is my code:
#pragma once
#include <string>
#include <map>
class Student
{
public:
Student(
double Score_Maths,
double Score_Eng,
double Score_Chem,
double Score_Bio,
double Score_His
);
~Student();
private:
std::string Surname;
std::map<std::string, double> Subject_Scores = { {"Maths"}, {"English"}, {"Chemistry"}, {"Biology"}, {"History"} };
};
What I'm trying to do is, to have those keys in class already and then initialize the values using constructor, but of course it shows error when initializing map like that, any help?
std::map<std::string, double> Subject_Scores = { {"Maths", 0.0}, {"English", 0.0}, {"Chemistry", 0.0}, {"Biology", 0.0}, {"History", 0.0} };optional<double>it can actually not have a value, rather than just having a magic "invalid" value. But this seems like a lot of complexity without much payoff.