I am working with two classes each in their own .h file (although I think I only need to show one on here). I am using a different .cpp to define contents of each class and writing the rest of the code to start things off from main.cpp. I am making a menu to keep track of items (their price description, name, and quantity) which I believe I have mostly figured out. However, I am generating these errors:
Error 1:
Tests that GetNumItemsInCart() returns 6 (ShoppingCart)
Compilation failed
Compilation failed
main.cpp: In function ‘bool testPassed(std::ofstream&)’:
main.cpp:24:24: error: no matching function for call to ‘ShoppingCart::AddItem(ItemToPurchase&)’
cart.AddItem(item);
^
In file included from main.cpp:8:0:
ShoppingCart.h:21:11: note: candidate: void ShoppingCart::AddItem()
void AddItem();
^~~~~~~
ShoppingCart.h:21:11: note: candidate expects 0 arguments, 1 provided
Error 2:
Test that GetCostOfCart() returns 10 (ShoppingCart)
Compilation failed
Compilation failed
main.cpp: In function ‘bool testPassed(std::ofstream&)’:
main.cpp:23:21: error: no matching function for call to ‘ShoppingCart::AddItem(ItemToPurchase&)’
cart.AddItem(item);
^
In file included from main.cpp:8:0:
ShoppingCart.h:21:11: note: candidate: void ShoppingCart::AddItem()
void AddItem();
^~~~~~~
ShoppingCart.h:21:11: note: candidate expects 0 arguments, 1 provided
main.cpp:27:21: error: no matching function for call to ‘ShoppingCart::AddItem(ItemToPurchase&)’
cart.AddItem(item);
^
In file included from main.cpp:8:0:
ShoppingCart.h:21:11: note: candidate: void ShoppingCart::AddItem()
void AddItem();
^~~~~~~
ShoppingCart.h:21:11: note: candidate expects 0 arguments, 1 provided
Lastly here is code i believe to be relevant:
ShoppingCart.h
class ShoppingCart {
public:
ShoppingCart();
ShoppingCart(string name, string date);
1. Please edit your post to put [code][/code] tags around your code.
> main.cpp:24:24: error: no matching function for call to ‘ShoppingCart::AddItem(ItemToPurchase&)’
You're saying you pass a parameter containing the item to be added.
> void ShoppingCart::AddItem()
You're also saying that you don't need a parameter, and you're going to read the item directly from cin.
Your existing implementation is wrong. Reading the specifics of an item should be a method in your ItemToPurchase class.
This should be all you need, and would seem to conform to the expected interface your automated test is expecting.