I've written a very simple class (called Region) that puts a line on the screen in the constructor and one in the destructor. I have a static int in that class keeping the number of instances (incremented by one in every constructor) and a private int that keeps the id of every instance (so in the constructor I have mynumber = numberofinstances).
This being said, this is the code (it is testcode, I was checking how vector does its destruction):
printf("after creation vector");
printf("after first pushback");
printf("after second pushback");
On screen I get:
Constructor Region: instances:0 // creating my 2 instances
Constructor Region: instances:1
after creation vector
after first pushback
destructor Region class for number 0 // ?? why here
after second pushback
destructor Region class for number 1 // destructor vector
destructor Region class for number 0
destructor Region class for number 1 // out of scope second object due to }
destructor Region class for number 0 // out of scope first object due to end of method
I don't understand this. I do understand that my objects get destroyed twice, once for getting out of scope and once by the destructor of the vector.
But I don't understand the parts with the "??" next to them.
Can anyone explain this ?