I'm trying to create a map of two different classes, but can't seem to set a value to a key. Here's my code:
The error is "no matching function call to Course()" - any ideas?
Code:
#include <map>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
class Student {
public:
Student(const string& si, const vector <string>& c) : student_id(si), courses(c) {}
const string& getStudentId() const { return student_id; }
void setStudentId(string si) { student_id = si; };
private:
string student_id;
vector <string> courses;
};
class Course {
public:
Course(const string& cc, const int& ts) : course_code(cc), time_slot(ts) {}
const string& getCourseCode() const { return course_code; }
void setCourseCode(string cc) { course_code = cc; };
private:
string course_code;
int time_slot;
};
bool operator< (const Course& left, const Course& right)
{ return left.getCourseCode() < right.getCourseCode(); }
bool operator< (const Student& left, const Student& right)
{ return left.getStudentId() < right.getStudentId(); }
int main ()
{
vector <string> v1; v1.push_back("2"); v1.push_back("3");
Student s1 = Student("1", v1);
Course c1 = Course("6", 7);
map < Student, Course > schedule;
map < Student, Course > :: iterator map_itr;
string :: iterator string_itr;
vector <string> vector_itr;
map_itr = schedule.begin();
schedule[s1] = c1; //This line produces the error.
return 0;
}
The error is "no matching function call to Course()" - any ideas?