简体   繁体   中英

How should I keep track of several objects

I am trying to get better at programming and doing several exercises, I've found this article and I have issues with that Graduation question (the hardest one at the bottom) with the bunnies. I've made a bunny class and I am not sure how to keep track of the rabbits.

When I fill several rabbits into the array so when one of them dies how am I able to know which spot in array has been freed? Or what should I use to store the bunnies.

The assignment explicitly says that you should store bunnies in a linked list. You can use std::list (it has an erase member-function) (you can also implement your own list if you want to as an exercise).

you need to have a structure of type bunny with fields sex, male,age etc. and then create a std::vector of bunnies and change the value (eg. increment age) of the structures while iterating. once some conditions are fulfilled like age>10,then vector.erase that bunny.

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