Bradley Bradley - 11 months ago 70
C++ Question

C++ Class Set, skip first 2 values

I have a class set up at the top of my program called InventoryVector, this stores all items in the program, product name, price and quantity.

Through the admin section of the program the product name, price and quantity have allready been defined, my question is when the user picks a item to purchse then i need to lower the available quantity of that item.

This is what i have come up with:


I need to skip the VOID part and leave these unedited, I only want to replace the 3rd variable in the class with (test)

Simply put, my question is just, how to i skip the first 2, leave them untouched and only edit the 3rd.

Here is the function storing the information :

void setInventory(string x, double y, int z) {
sProductName = x;
dProductPrice = y;
iQuantity = z;

Answer Source

If your class does not have a single property setter and you can't change it, you probably have to use something like

auto& ref = InventoryVector[i]; // for brevity
ref.setInventory(ref.getProductName(), ref.getProductprice(), test);