Use pointer of pointers or just a pointer?

Pages: 12
If every Dinosaur object only ever contains one dinosaur, then why do you need to store its number of dinosaurs as a data member? You know the value will always be 1.

All you need is for the cage to record the number of dinosaurs you put into it.
Last edited on
closed account (23q2T05o)
Yeah but how I can record the number of dinos I put into it?
Last edited on
Every time you but a dinosaur in, increase the number by 1. I mean... basic counting, right?
closed account (23q2T05o)
Okay but can I use my way?
I mean, obviously you could. You could make each Dinosaur objects store the number 1 in a data member, and then loop over your objects and read the number 1 from each one, and add together all the number 1's you've read from each one.

But what on earth would be the point? Why would you waste your time putting such pointless code in to store the same number in each Dinosaur object, when you know what that number is going to be anyway? Cluttering code with useless stuff is never a good thing to do.
Topic archived. No new replies allowed.
Pages: 12