object holding a list

i have this strange error, i have isolated where the error might be in the below code

also, i tried to out this list<Item> bag; as part of the character object too


1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\list(1194): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'Item' (or there is no acceptable conversion)
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\exception(470): could be 'bool std::operator ==(const std::_Exception_ptr &,const std::_Exception_ptr &)'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\exception(475): or       'bool std::operator ==(std::_Null_type,const std::_Exception_ptr &)'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\exception(481): or       'bool std::operator ==(const std::_Exception_ptr &,std::_Null_type)'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\system_error(408): or       'bool std::operator ==(const std::error_code &,const std::error_condition &)'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\system_error(416): or       'bool std::operator ==(const std::error_condition &,const std::error_code &)'
1>          while trying to match the argument list '(Item, const Item)'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\list(1188) : while compiling class template member function 'void std::list<_Ty>::remove(const _Ty &)'
1>          with
1>          [
1>              _Ty=Item
1>          ]
1>          c:\users\gregory\documents\visual studio 2010\projects\smallfantasy\smallfantasy\character.h(22) : see reference to class template instantiation 'std::list<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=Item
1>          ]
1>  Generating Code...
1>  Compiling...
1>  Character.cpp
1>  Generating Code...
1>  Compiling...
1>  main.cpp
1>  Story.cpp
1>  Consumable.cpp
1>  Combat.cpp
1>  Generating Code...
1>c:\users\gregory\documents\visual studio 2010\projects\smallfantasy\smallfantasy\story.cpp(17): warning C4715: 'Stat' : not all control paths return a value
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef ITEM_H
#define ITEM_H
#include "Character.h"
#include "Story.h"
#include "Misc.h"
#include <string>
#include <list>
using namespace std;

class Item
{
protected:
	string item_Name;
	int goldValue;

public:
	void addItem(list<Item>,Item); 
	void deleteItem(list<Item>,Item);
	void clearItemInvent(list<Item>);
	void Buy_Item();
	void Sell_Item();
	virtual void display(){}

};

class Consumable: public Item
{
private:
	int item_Health;
	int item_Mana;
public:

	void Consume();
	void display();

};
class Equipment:public Item
{
protected:
	short item_Stat_A;
	short item_Stat_MA;
	short item_Stat_DEF;
	short item_Stat_MDEF;

public:
	void Equip();
	void display();
};

class Weapon : public Equipment
{
protected:

public:

};

class Armor : public Equipment
{
protected:

public:

};
#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include"Item.h"
#include"Character.h"
#include <algorithm>
#include <list>
using namespace std;

void Item::addItem(list<Item> invent, Item item)
{	
	invent.push_back(item);
}
void Item::deleteItem(list<Item> invent, Item item)
{
	invent.remove(item);
}
void Item::clearItemInvent(list<Item> invent)
{
	invent.clear();
}
std::list::remove() needs a way to know if two elements are equal (¿how could decide when to erase?)

Apart, methods should operate with the state of the object. However your code makes it so it does not matter to who you send the message to.
It's specially aggravating that an item (any item) is responsible for clearing an inventory.
thanks for your assistance, i figured it out. i will just make item_ID part of the object so that i can compare it so that it can beremove()
Topic archived. No new replies allowed.