timisaberry
timisaberry

Reputation: 34

Variable sized pointer array

Asteroid* rocks[maxAsteroids] = {};

So Asteroids is a pointer to a class, at least thats how I understand it. My question is I can't have maxAsteroids be a const, and I know it can't be a simple variable. So what is the proper way to initialize a variable size to a pointer array? This feels like a misunderstanding on my part of syntax, but I'm just not getting it. Appreciated!

Upvotes: 0

Views: 116

Answers (1)

Aesthete
Aesthete

Reputation: 18850

std::vector<Asteroid*> roids;
roids.resize(maxAsteroids);

Upvotes: 2

Related Questions