How do you declare this line(s) of code?

1
2
3
4
5
6
7
8
9
10
11
void initialize(invType& inv){
 createItem (inv.item[0], "10300", "Nutella", "Ferrero", 10);
 createItem (inv.item[1], "10475", "Almonds", "Members Mark", 27);
 createItem (inv.item[2], "14310", "Peas & Carrots", "Libbys", 230);
 createItem (inv.item[3], "15730", "Tomato Paste", "Hunts", 400); 
 createItem (inv.item[4], "29500", "Cranberry Juice", "Ocean Spring", 85);
 createItem (inv.item[5], "30475", "Orange Juice", "Florida's Choice", 98);
 createItem (inv.item[6], "34330", "Eggs", "Centeral Market", 78);
 createItem (inv.item[7], "56900", "Eggs", "Eggland's Best", 100);  
 inv.total=8;          
}


So, I have to use this and I was wondering how do you declare the type
"invType" inv.

Thanks .
Well it looks to me like your inventory is a class that allocates memory inside an array/other container- this doesn't seem like a well designed class however... it's not self contained. However I'm sure there are lot's of ways you could create a quick little class that preforms this ... questionable... purpose.

(IMHO) a better interface for something like this would perhaps look like this:

1
2
3
4
5
6
7

Inventory inv;
inv.add("10300", "Nutella","Ferrero",10);
//etc etc etc

item* itemPointer = inv.get("10300"); //  IF you don't have any duplicates could also inv.get(0);


Reviewing the question, you could perhaps have another, different question. How do you actually make a new instance of invType?

if that's the case, you'd do something like this (I obviously don't have your code, so this is what I'd expect)

1
2
invType inv;
initialize(inv);


Oh, yeah I know there's better ways, but since we haven't "learned" the subject in class yet, we're not allowed to use it. So I have to use the exact code as I mentioned above. :x. And yeah, I wanted to do it your way, but I'm not sure if it's allowed. I'd have to ask my TA .

I did do
1
2
invType inv;
initialize(inv);

but my compiler says invType is undeclared .
Last edited on
we're not allowed to use it.

I hate all professors that actually do this. My local uni doesn't have any but that makes me angry.
Yeah, I feel the same way sometimes.

Topic archived. No new replies allowed.