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.
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