Dynamic Object Creation
Posted: Sun Oct 31, 2010 3:32 am
Hello there,
I've been using C++ for awhile now but just started with game development kind of recently. I recently ran into a problem when starting to work on a new game, I'm not sure if I'm missing something from basic C++ or I'm just looking at the problem wrong. Basically, I'm not sure how to dynamically create objects when I'm not sure of how many objects I will need (if that makes sense/if I'm using the right terminology).
With things like bullets that I have a set maximum for, I can use an array. For example: I can have a bullet class (lets call it 'bullet') and a player class that has an array like:
But what I want to know is how I would go about doing the same as with bullets, except without having a limit on how many I could have. Using a small array of 20 when I might not fill the entire array isnt really all that detrimental, but when I might have a lot more of a particular object being used I wouldnt want to have a bunch of huge arrays for things that might only have 1 or 2 members used.
So, am I missing something in basic c++ that I should go back and learn? When I've tried Google for this I've come up with nothing helpful so I would assume that my problem is simply missing something that I should know from learning C++ or I'm just looking at this problem in the wrong way. I'm just hoping one of you could point me in the right direction, thanks in advance!
I've been using C++ for awhile now but just started with game development kind of recently. I recently ran into a problem when starting to work on a new game, I'm not sure if I'm missing something from basic C++ or I'm just looking at the problem wrong. Basically, I'm not sure how to dynamically create objects when I'm not sure of how many objects I will need (if that makes sense/if I'm using the right terminology).
With things like bullets that I have a set maximum for, I can use an array. For example: I can have a bullet class (lets call it 'bullet') and a player class that has an array like:
Code: Select all
class bullet;
class player{
//other stuff for player class here
private:
bullet bullets[20];
};
So, am I missing something in basic c++ that I should go back and learn? When I've tried Google for this I've come up with nothing helpful so I would assume that my problem is simply missing something that I should know from learning C++ or I'm just looking at this problem in the wrong way. I'm just hoping one of you could point me in the right direction, thanks in advance!