+ 2
Count number of objects in C++?
Is there a way to count the number of objects in c++? For example, in this code right above the name of each person, ai want it to output "Person #2" or something like that. https://code.sololearn.com/c454ZOctiB5J/?ref=app I've been trying to figure this out for a while lol
2 Answers
+ 7
In the Human constructor:
static int id = 1;
// ...rest of code...
id++;
And you can now use the id integer in your code. You could also set an id property to each Human, if you want.
+ 2
Ooh it works
Thanks
I didn't think about using static because I entirely forgot about it's existence xD
Now I'm trying to figure out a random 4 digit ID for each human