I am getting errors and I feel that is is a small mistake (like a typo or something and I just can't find it. I am hoping that a fresh set of eyes could spot it. I am not done with this project but I would like to clean up some errors before going forward. Any help would be awesome. Here is my code and errors:
List.cpp
1>c:\users\friedmann\desktop\data structures\assignment 4\list\list\list.cpp(24): error C2661: 'std::list<_Ty>::insert' : no overloaded function takes 1 arguments
1> with
1> [
1> _Ty=int
1> ]
1>c:\users\friedmann\desktop\data structures\assignment 4\list\list\list.cpp(45): error C2039: 'item' : is not a member of 'std::list<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
1>c:\users\friedmann\desktop\data structures\assignment 4\list\list\list.cpp(49): error C2039: 'item' : is not a member of 'std::list<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
1>c:\users\friedmann\desktop\data structures\assignment 4\list\list\list.cpp(53): error C2039: 'item' : is not a member of 'std::list<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
1>c:\users\friedmann\desktop\data structures\assignment 4\list\list\list.cpp(57): error C2039: 'item' : is not a member of 'std::list<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
1>c:\users\friedmann\desktop\data structures\assignment 4\list\list\list.cpp(60): error C2039: 'item' : is not a member of 'std::list<_Ty>'
1> with
1> [
1> _Ty=int
1> ]
None of the insert declarations have just one parameter. That's what the compiler is complaining about.
You need to say _where_ you want to insert.
Depending what you're trying to do, solutions for line 19 are:
front.insert(front.begin(), rand()%5);
or
front.push_back(rand()%5);
As regards the function starting at line 30, it has numerous problems. Count variables not initialized, *List not initialized, iterator i is not used, typo in line 55, function never returns a value, so counts are lost, parameter item is not used, all items are counted each time, parameters badly named, etc.
Try:
1 2 3 4 5 6 7 8 9 10
int countValue(const list<int>& int_list, constint value)
{
int count = 0;
for(list<int>::const_iterator it = int_list.begin(); it != int_list.end(); ++it)
{
if(*it == value)
++count;
}
return count;
}