loadidng array

Hi there i am trying to create an array using classes which i have made.
Also i want to (load)bullets and shotgunshells into a dynamic array. I'm having issues with how to (load) 2 different objects into an array which is Arsenal. And i am wanting to easily be able to randomly generate numbers for both objects the abullets and aShot.

1
2
3
4
5
6
7
8
9
10
11
 	AmmunitionManager Arsenal[10];
	Bullet aBullets[5];
	ShotgunShell aShot[5];

	for(int i = 0; 0<6; i++)
	{
		aBullets[i].setDamage(22);
		aShot[i].setDamage(23);
		system("pause");
	}
i want to (load)bullets and shotgunshells into a dynamic array

If you want to use a dynamic array, I suggest you use a std::vector. A vector is an extensible array of objects of a type that you specify.
http://www.cplusplus.com/reference/vector/vector/

how to (load) 2 different objects into an array which is Arsenal.

To do this, you need to use polymorphism. Both Bullet and ShotgunShell need to inherit from a shared class.
http://www.cplusplus.com/doc/tutorial/polymorphism/
You were given an example of polymorpism here:
http://www.cplusplus.com/forum/beginner/132788/

i am wanting to easily be able to randomly generate numbers for both objects the abullets and aShot.

Use the srand() and rand() functions.
http://www.cplusplus.com/reference/cstdlib/rand/



Last edited on
Thank you.
Topic archived. No new replies allowed.