Multimap problem

Hello. I get "error C2664: 'bool NameCompare::operator ()(Product &,Product &)' : cannot convert argument 1 from 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'Product &'" when trying to compile this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<map>
using namespace std;
class Product
{
public:
	Product(string name, double price, string producer);
	~Product();
	double returnprice() const
	{
		return this->price;
	} 
	string returnproducer() const
	{
		return this->producer;
	} 
	string returnname()const
	{
		return this->name;
	}
	

private:
	string name;
	double price;
	string producer;

};
Product::Product(string name, double price, string producer) : name(name), price(price), producer(producer)
{
}
Product::~Product()
{
}
struct NameCompare
{
	bool operator () ( Product &one, Product &two)
	{
		return one.returnname()<two.returnname();
	}
};
int main()
{
	multimap<string, Product, NameCompare>shop_name;
	Product temp = Product("abv", 3.3, "qwerty");
	shop_name.insert(pair<string, Product>("abv", temp));
}
A multimap's compare operator compares keys, not values. Your multimap uses strings as keys and Product objects as values, while your compare operator expects Product objects as keys.
Thanks.
But since multimap has value_compare member I could do it different way. Right?
Topic archived. No new replies allowed.