Hello, can someone help with this code ? its not compiling and I am having such hard time fixing it. This is regarding a lab I'm working on.
-----------------------------------------------------------------------
Failed to compile
ShoppingCart.cpp: In member function ‘void ShoppingCart::add(ItemToPurchase&)’:
ShoppingCart.cpp:65:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < item.size(); i++)
~~^~~~~~~~~~~~~
ShoppingCart.cpp: In member function ‘void ShoppingCart::remove(std::__cxx11::string)’:
ShoppingCart.cpp:101:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < item.size(); i++)
~~^~~~~~~~~~~~~
ShoppingCart.cpp: In member function ‘void ShoppingCart::update(ItemToPurchase&)’:
ShoppingCart.cpp:143:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < item.size(); i++)
~~^~~~~~~~~~~~~
ShoppingCart.cpp:155:15: error: ‘__gnu_cxx::__alloc_traits<std::allocator<ItemToPurchase> >::value_type {aka class ItemToPurchase}’ has no member named ‘SetDescription’
item.at(i).SetDescription(updateItem.GetDescription());
^~~~~~~~~~~~~~
ShoppingCart.cpp:155:41: error: ‘class ItemToPurchase’ has no member named ‘GetDescription’
item.at(i).SetDescription(updateItem.GetDescription());
^~~~~~~~~~~~~~
ShoppingCart.cpp: In member function ‘void ShoppingCart::showDescription()’:
ShoppingCart.cpp:197:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < item.size(); i++)
~~^~~~~~~~~~~~~
ShoppingCart.cpp:201:55: error: ‘__gnu_cxx::__alloc_traits<std::allocator<ItemToPurchase> >::value_type {aka class ItemToPurchase}’ has no member named ‘GetDescription’
cout << item.at(i).GetName() << " : " << item.at(i).GetDescription() << endl;
^~~~~~~~~~~~~~
ShoppingCart.cpp: In member function ‘void ShoppingCart::showCart()’:
ShoppingCart.cpp:227:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < item.size(); i++)
~~^~~~~~~~~~~~~
The "comparison between signed and unsigned integer expressions" is just a warning. Warnings can be just as bad as an error, but they don't stop the code from compiling.
The following are your errors. They are saying that "SetDescription" and "GetDescription" don't exist in the "ItemToPurchase" class.
ShoppingCart.cpp:155:15: error: ‘__gnu_cxx::__alloc_traits<std::allocator<ItemToPurchase> >::value_type {aka class ItemToPurchase}’ has no member named ‘SetDescription’
item.at(i).SetDescription(updateItem.GetDescription());
ShoppingCart.cpp:155:41: error: ‘class ItemToPurchase’ has no member named ‘GetDescription’
item.at(i).SetDescription(updateItem.GetDescription());
ShoppingCart.cpp:201:55: error: ‘__gnu_cxx::__alloc_traits<std::allocator<ItemToPurchase> >::value_type {aka class ItemToPurchase}’ has no member named ‘GetDescription’
cout << item.at(i).GetName() << " : " << item.at(i).GetDescription() << endl;
thanks you very much guys, I was able to fix the "for loop" but I am still trying to get around the ones that "duch" suggested with little to no luck at all.
Any other suggestions for the below errors ?
ShoppingCart.cpp: In member function ‘void ShoppingCart::update(ItemToPurchase&)’:
ShoppingCart.cpp:155:15: error: ‘__gnu_cxx::__alloc_traits<std::allocator<ItemToPurchase> >::value_type {aka class ItemToPurchase}’ has no member named ‘SetDescription’
item.at(i).SetDescription(updateItem.GetDescription());
^~~~~~~~~~~~~~
ShoppingCart.cpp:155:41: error: ‘class ItemToPurchase’ has no member named ‘GetDescription’
item.at(i).SetDescription(updateItem.GetDescription());
^~~~~~~~~~~~~~
ShoppingCart.cpp: In member function ‘void ShoppingCart::showDescription()’:
ShoppingCart.cpp:201:55: error: ‘__gnu_cxx::__alloc_traits<std::allocator<ItemToPurchase> >::value_type {aka class ItemToPurchase}’ has no member named ‘GetDescription’
cout << item.at(i).GetName() << " : " << item.at(i).GetDescription() << endl;