multimap inside class accept stuct

Hello guys
I am stuck in a small part .
How do you declare a class
class test{

private:
multimap<int, stuct member<;
};
its not working with me , can someone tell me the right formate , i tired to search the web but i couldnt find what i need.
thanks
This is what i am trying to achive :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class students :public element
{
	/*Type student has data fields that can store: a student’s ID (e.g. 4567843), 
		a student’s first and last names (e.g. John Smith), a list of grades 
		(e.g. 64.4, 45, 78.25, 90- all out of 100), and a string letter-grade (e.g., A-)*/
public:
	struct student{
		int id;
		string name;
		//list<int> grade;
		//string l_g;
	};	
	students(){}
//	students plus(const students&);
	void insert(students&,int,student)
private:

	multimap<int,student> table;
};
void insert(students& student,int index,student student1){
	student.table.insert(pair<int,student>(index,student1));
}
It looks like there is a missing semicolon at the end of line 15. The function, on line 20, should be a member function (students::insert). Also, in the definition of insert, change the parameter named student so that it is not the same as the type student. Does that help?
Last edited on
A couple of problems.

1
2
3
void students::insert(students& st,int index,student student1){
	st.table.insert(std::make_pair(index,student1));
}


Your two problems: insert() is a member function of students, so to implement it outside
the class declaration requires the students:: scope to be explicitly stated.

Second, you can't declare a variable with the name 'student' because you
already declared 'student' to be a type.

(Third, not so much: use std::make_pair() instead of constructing the std::pair yourself.
It's not a problem, it's just easier to read and maintain.)

Also, note that you may want to define operator< for student so that the map can sort the elements and the find method can do look-ups.
Last edited on
Evidently the std::less will work fine because the key is simply an integral value. The instance of students is the value not the key.

Why does insert take references to two students objects? It is already a non-static member function of the students type so why doesn't it insert into its own table? That is very bizarre. What are you trying to do?
Good catch. I was thinking of actually comparing pair to pair, but that wouldn't be the case.
Topic archived. No new replies allowed.