pass pointer,, return pointer???
Hey all,
I am tryin to cut down the size of my program by creating a new class to perform certain operations. I would like to declare an array in my main, pass the array to EACH function in the new class, and have some value be inserted into the same array and be saved. My main is such: Code:
SoldItem *sold = new SoldItem[5]; Code:
OperateSold::OperateSold(){ } DO i need to return a pointer to the array?? Or is the passing SoldItem pointer going to insert the char amount in the proper memory location for the array. THanks very much |
You don't need to return the pointer; the way you're doing it should work.
It might be cleaner to have the sold array be a member of the OperateSold object and only access it though that class. That way you don't end up with a global array that magically changes when you call functions on the OS object (counterintuitive). |
HMM interesting point,
THe only issue is, that i need to referende the sold array in other functions in the main class. Can i have a function in OperateSold, that will return the array so i can use sold[i] in other functions??? |
of course. Another way to do it would be a function like
Code:
SoldItem* OperateSold::getSoldItem(int i) { return &sold[i]; } Doesn't really matter though. whatever looks right to the maintainer (you!) is best :D |
All times are GMT -5. The time now is 03:02 PM. |