So I have a student class with a map for course names and grades and I dont know the syntax for the constructor in main.
class Student{
public:
const string& name;
const string& personalInfo;
map<string,int> grade_list;
Student(const string &name, const string &personalInfo, map<string, int> gradeList)
: name(name), personalInfo(personalInfo), grade_list(gradeList) {}};
int main(){
Student s("Arthur","english student",{"French",5});
}
You have a syntax error as you already guessed. Fix it like this:
Student s("Arthur", "english student", {{"French",5}} );
You need to curly-brace the map and its values.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.