I wish that , but of course when I try to implement it it doesn´t work!!!
When I declare a queue in main like this, it works!
Code:
#include <iostream>
#include <queue>
using namespace std;
int main()
{
queue<int> aqueue;
aqueue.push(12);
aqueue.push(123);
aqueue.push(1234);
aqueue.push(12345);
int aqueuesize = aqueue.size();
for (int i = 0; i < aqueuesize; i++)
{
cout << "Value nr " << i+1 << " " << aqueue.front() << endl;
aqueue.pop();
}
return 0;
}
but in mine Person-class it doesn´t
Code:
Person::Person()
{
//If queue is empty then do as usual
if (idqueue.empty())
itsId = id++;
//Or if it isn´t
else
{
//retrieve 'lost id number' (front item)
itsId = idqueue.front();
//remove the front item
idqueue.pop();
}
}
Person::~Person()
{
//When deleting a person push that id on a queue
idqueue.push(itsId);
}
When I print out some debug I´ve noticed some strange things, in the deconstructor of Person it pushes the right value every time but the size of the queue reamains at 1 all the time. I´ve deleted
like 10 Persons one after one but still it insist that only 1 element is in the queue.
And every time the constructor is invoked the queue seems to be empty.
What am I doing wrong???