initialize class array "correctly"

Oct 30 2011 6:38 AM
Right, I have a simple class for any upgrade the player can get, including an array containing the cost of each upgrade level, so my initialization looks like:

myUpgrade.description="some description here";
myUpgrade.maxUpgrade=10;
myUpgrade.upgradeCostArray[0]=100;
myUpgrade.upgradeCostArray[1]=230;
myUpgrade.upgradeCostArray[2]=233;
.
.
myUpgrade.upgradeCostArray[9]=12233;



As you can see this doesn't look too good- I have a predefined size 10 int array in my class, AND if any value in the array that is below maxUpgrade is not initialized it will only show up during runtime.  Is there a cleaner way of doing this, perhaps somehow with a constructor?

Answers (4)