I am having trouble with classes. So I have three different classes: store, customer and product. In the store class I want to be able to add a customer. The problem is the way I need to add the customer does not follow the way customer was called in customer.h. This is what I have from store.h:
void addCustomer(int customerID, string customerName);
in customer.h I have:
Customer();
Customer(string name, int customerID, bool credit);
in customer.cpp I have:
Customer::Customer(string name, int customerID, bool credit) :
name(name), customerID(customerID), credit(credit){}
and in store.cpp I have the following:
void Store::addCustomer(int customerID, string customerName){
bool credit = false;
Customer addCustomer(int customerID, string customerName);
Customer* customer = new Customer(name = "Null", customerID = 0, credit);
customers.push_back(customer);
for (int i = 0; i < customers.size(); ++i) {
if (customers.at(i)->getID() == customerID){
throw runtime_error("Customer already added.");
}
}
}
the exception is to be thrown if the customer has already been added in to the vector. Everything else works for example all of the get and set functions for all three classes but this one block of code wont work and I do not even get an error the program just wont run any further than a certain point. What am I doing wrong?