Please take a look at the following:
type = appleJuice;
type = orangeJuice;
type = mangoLassi;
type = fruitPunch;
as you can see i have stored different objects in the "type"Array.
The dispenserType class has a constructor that sets the number of items to 20.
so we have int variable numberfItems for the object appleJuice set to 20 so on and so forth.
The same class has also the following methods: method that decreases the numberOfItems by one:
int dispenserType::getNoOfItems() const
If for example the following is called,
, and subsequently,
cout<< appleJuice.getNoOfItems() << endl;
. the program would display the right numberOfItmes which is 19. On the other hand, if
, it would display the number 20.
That behavior leads me to think that appleJuice and typeare two separate objects.
My questions is, is there a way to create an array of objects without needing to declare an object and store in an array as I did it as I did?