简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM