Problem with Inventory class

Hello. Basically, I am attempting to make an inventory class for a text game and I am getting a single error, and I really cannot pinpoint the problem. It is, apparently, due to the 'find' algorithm but I cannot see what is wrong with my code. The error is a Semantic issue, according to Xcode. Additionally, unrelated to the above problem, function Pick_Item() does not ouput the contents of the map, as it is supposed to.
for(auto index=Backpack.begin();index!=Backpack.end();index++)
{
cout << index->first << " : " << index->second << endl;

}

It is either blank or would only show one item individually. Input on these two problems with the class would be appreciated :). By the way, if the class seems incomplete, it is. I was unable to finish it due to the recurring error.
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
class Inventory
{
public:
    map<int, string>Backpack;
    

private:
    int number_of_items;
    int item_number;
    string item_name;
    
public:
    
    
    Inventory () {};
    Inventory(const int& item_num, const string& name_of_item)
    {
        item_number = item_num;
        item_name=name_of_item;
        
        
    }
    
    void Insert_To_Backpack()
    {
        Backpack.insert(make_pair(item_number, item_name));
        cout << item_name << " inserted into your backpack" << endl;
        
    }
    
    
    void Display_Item( int& item_number1)
    {
        auto finder= find(Backpack.begin(), Backpack.end(), item_number1);
        if(finder!=Backpack.end())
        {
       
            auto thing = Backpack[item_number1];
            cout << thing << endl;
            
        }
    }
    
    void Pick_Item()
    {
        cout << "Enter the number of the item you are searching for. The options are as follows: " << endl;
        for(auto index=Backpack.begin();index!=Backpack.end();index++)
        {
            cout << index->first << " : " << index->second << endl;
            
        }
        
        auto item_to_search=1;
        cin>>item_to_search;
        auto find_item = find(Backpack.begin(), Backpack.end(), item_to_search);
        if(find_item!=Backpack.begin())
        {
            cout << "Item found" << endl;
            Display_Item(item_to_search);
            
        }
       
    }
What exactly is the first error? All you say is that an error exists, but provide no explanation on what the error is.

As for the second error, I don't see anything obviously wrong. My guess is the map isn't being populated for whatever reason. Have you ran this through a debugger and inspected the map at the time of that function call?
Some obvious problems:
Line 34: find needs to be qualified by the object (Backpack).
find doesn't take 3 arguments.
Line 55: find needs to be qualified by the object (Backpack)
find doesn't take 3 argumentss.
Line 56: You want to test != Backpack.end() (not begin())
Line 64: You're missing the }; for the class declaration.

Resident Biscuit:
Invalid operands to binary expression, problem with:// find

template <class _InputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_InputIterator
find(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
for (; __first != __last; ++__first)
if (*__first == __value_)
break;
return __first;
}
in specific the line before break;
Thanks for the corrections AbstractionAnnon
Topic archived. No new replies allowed.