I don't understand this error feedback

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);

void SetCustomerName(string name);
void SetDate(string date);
void AddItem();
void RemoveItem();
void ModifyItem();

void PrintTotal() const;
void PrintDescriptions() const;
void PrintMenu() const;

int GetNumItemsInCart() const;
int GetCostOfCart() const;
string GetCustomerName() const;
string GetDate() const;

private:
string customerName;
string currentDate;
vector<ItemToPurchase> cartItems;
};


ShoppingCart.cpp



// constructor
ShoppingCart::ShoppingCart(){
this-> customerName = "none";
this-> currentDate = "January 1, 2016";
}

ShoppingCart::ShoppingCart(string name, string date) {
customerName = name;
currentDate = date;
}


// Add Item
void ShoppingCart::AddItem() {
ItemToPurchase currItem;


string inputName;
string inputDescription;
int inputPrice;
int inputQuantity;



cout << "ADD ITEM TO CART" << endl;

cout << "Enter the item name:" << endl;
getline(cin, inputName);
currItem.SetName(inputName);

cout << "Enter the item description:" << endl;
getline(cin, inputDescription);
currItem.SetDescription(inputDescription);

cout << "Enter the item price:" << endl;
cin >> inputPrice;
currItem.SetPrice(inputPrice);

cout << "Enter the item quantity:" << endl << endl;
cin >> inputQuantity;
currItem.SetQuantity(inputQuantity);

cin.ignore();

cartItems.push_back(currItem);
}
// End of add item






//Print Menu

void ShoppingCart::PrintMenu() const {

ShoppingCart items;
char menuInput;
bool forMenu;

string lastInputName = customerName;
string lastInputDate = currentDate;

items.SetCustomerName(lastInputName);
items.SetDate(lastInputDate);



cout << "MENU" << endl;
cout << "a - Add item to cart" << endl;
cout << "d - Remove item from cart" << endl;
cout << "c - Change item quantity" << endl;
cout << "i - Output items' descriptions" << endl;
cout << "o - Output shopping cart" << endl;
cout << "q - Quit" << endl << endl;

cout << "Choose an option:" << endl;

menuInput = getchar();
cin.ignore();

forMenu = true;

while (forMenu == true) {


switch (menuInput) {

case 'q':
forMenu = false;
break;

case 'a':

items.AddItem();

cout << "MENU" << endl;
cout << "a - Add item to cart" << endl;
cout << "d - Remove item from cart" << endl;
cout << "c - Change item quantity" << endl;
cout << "i - Output items' descriptions" << endl;
cout << "o - Output shopping cart" << endl;
cout << "q - Quit" << endl << endl;

cout << "Choose an option:" << endl;

break;


case 'd':
items.RemoveItem();

cout << "MENU" << endl;
cout << "a - Add item to cart" << endl;
cout << "d - Remove item from cart" << endl;
cout << "c - Change item quantity" << endl;
cout << "i - Output items' descriptions" << endl;
cout << "o - Output shopping cart" << endl;
cout << "q - Quit" << endl << endl;

cout << "Choose an option:" << endl;

break;


case 'c':
items.ModifyItem();

cout << "MENU" << endl;
cout << "a - Add item to cart" << endl;
cout << "d - Remove item from cart" << endl;
cout << "c - Change item quantity" << endl;
cout << "i - Output items' descriptions" << endl;
cout << "o - Output shopping cart" << endl;
cout << "q - Quit" << endl << endl;

cout << "Choose an option:" << endl;

break;


case 'i':
items.PrintDescriptions();

cout << "MENU" << endl;
cout << "a - Add item to cart" << endl;
cout << "d - Remove item from cart" << endl;
cout << "c - Change item quantity" << endl;
cout << "i - Output items' descriptions" << endl;
cout << "o - Output shopping cart" << endl;
cout << "q - Quit" << endl << endl;

cout << "Choose an option:" << endl;

break;


case 'o':
items.PrintTotal();

cout << "MENU" << endl;
cout << "a - Add item to cart" << endl;
cout << "d - Remove item from cart" << endl;
cout << "c - Change item quantity" << endl;
cout << "i - Output items' descriptions" << endl;
cout << "o - Output shopping cart" << endl;
cout << "q - Quit" << endl << endl;

cout << "Choose an option:" << endl;

break;


default:
cout << "Choose an option:" << endl;

break;
}
menuInput =getchar();
cin.ignore();
}
}



Main.cpp



int main() {

ShoppingCart myItems;

string inName;
string inDate;


cout << "Enter customer's name:" << endl;
getline(cin,inName);
myItems.SetCustomerName(inName);

cout << "Enter today's date:" << endl << endl;
getline(cin,inDate);
myItems.SetDate(inDate);

cout << "Customer name: " << myItems.GetCustomerName() << endl;
cout << "Today's date: " << myItems.GetDate() << endl << endl;

myItems.PrintMenu();
}
Last edited on
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.
1
2
3
void ShoppingCart::AddItem(ItemToPurchase& item) {
    cartItems.push_back(item);
}

Topic archived. No new replies allowed.