class Basket {
typedef bool (*Comp)(const Sales_item&,const Sales_item&);
public:
typedef std::multiset<Sales_item,Comp> set_type;
typedef set_type::size_type size_type;
typedef set_type::const_iterator const_iter;
Basket():items(compare) {}
void add_item(const Sales_item &item)
{
items.insert(item);
}
size_type size(const Sales_item &i) const
{
return items.count(i);
}
double total() const;
private:
std::multiset<Sales_item,Comp> items;
};
int main()
{
Basket basket;
Sales_item item1(Bulk_item("7-115-14554-7",99,20,0.2));
Sales_item item2(Item_base("7-115-14554-8",39));
Sales_item item3(Lds_item("7-115-14554-9",50,200,0.2));
Sales_item item4(Bulk_item("7-115-14554-7",99,20,0.2));
basket.add_item(item1);
basket.add_item(item2);
basket.add_item(item3);
basket.add_item(item4);
cout << basket.total() << endl;
return
0;
}
basket.add_item(item1);
basket.add_item(item2);
basket.add_item(item3);
basket.add_item(item4);
这里提示错误说没有用户定义的从Sales_item到const Sales_item的转换。。。怎么解决啊。只是用一个常引用传递实参而已。 |