Hello,
I'm working on a class that has a "queue" in which each instance waits to be serviced. The queue and all of its related variables are static, so all instances have access to the same queue. The queue itself is a dynamically allocated array of pointers to the class instances pointed to by a static pointer.
All I need the destructor to do is check to see if "this" is in the queue, if so remove it, and finally delete and reallocate the static pointer to a new array of the remaining queue.
This all seems to work, debugging shows that the code executes all the way to the ending bracket of the destructor. However the code does not execute after the delete statement in the main code. What is going on between the last line in the destructor and the next line in main?
Is there something more I need to do in the destructor? Am I using it wrong? Please help, I'm not very confident in my understanding of destructors and this problem is making my blood pressure very high X(.
int main{
myClass* myPointer;
myPointer = new myClass;
delete myPointer;
///////////////////////////////////////////code stops here
//...more code...
}
myClass::~myClass
{
if(QueueSize == 1)
{
QueueIndex = 0;
QueueCount = 0;
QueueSize = 0;
delete[] Queue;
}
else
{
myClass** QueueStorage = new myClass*[QueueSize];
if (PendingStatus) //PendingStatus is local, not static
{
unsigned char i = 0;
while (Queue[(QueueIndex + i) % QueueSize] != this)
{
i++;
}
QueueCount--;
while (i < QueueCount)
{
Queue[(QueueIndex + i) % QueueSize]
= Queue[(QueueIndex + i + 1) % QueueSize];
i++;
}
}
for (unsigned char i = 0; i < QueueCount; i++)
{
QueueStorage[i]
= Queue[(QueueIndex + i) % QueueSize];
}
delete[] Queue;
QueueSize--;
Queue = new myClass*[QueueSize];
for (unsigned char i = 0; i < QueueCount; i++)
{
Queue[i] = QueueStorage[i];
}
delete[] QueueStorage;
QueueIndex = 0;
}
myComputer.printf("done");///////////////////////this will execute!
}
Hello, I'm working on a class that has a "queue" in which each instance waits to be serviced. The queue and all of its related variables are static, so all instances have access to the same queue. The queue itself is a dynamically allocated array of pointers to the class instances pointed to by a static pointer.
All I need the destructor to do is check to see if "this" is in the queue, if so remove it, and finally delete and reallocate the static pointer to a new array of the remaining queue.
This all seems to work, debugging shows that the code executes all the way to the ending bracket of the destructor. However the code does not execute after the delete statement in the main code. What is going on between the last line in the destructor and the next line in main?
Is there something more I need to do in the destructor? Am I using it wrong? Please help, I'm not very confident in my understanding of destructors and this problem is making my blood pressure very high X(.