problem with DESTRUCTOR

Hi, problem is that in main i have only constructor and destructor of one Queue (it stays empty) but after my program back from destructor (destructor have only printf for checking) prints some strange stuff. Here is code:

- ELEMENT OF QUEUE -
- Elem.h -

#ifndef _ELEM_
#define _ELEM_

class Elem {
public:
int num;
Elem* next;

Elem(int n);
};

#endif

- Elem.cpp -

#include <stdlib.h>
#include "Elem.h"

Elem::Elem(int n)
{
num=n;
next=NULL;
}

- QUEUE -
- Queue.h -

#ifndef _Queue_
#define _Queue_

class Elem;

class Queue {
public:
Elem *first, *last;
int length;

Queue();
~Queue();
};

#endif

- Queue.cpp -

#include <stdlib.h>
#include <stdio.h>
#include "Queue.h"
#include "Elem.h"

Queue::Queue()
{
first=NULL;
last=NULL;
length=0;
}

Queue::~Queue()
{
if((first==NULL)&&(last==NULL)) printf("D E S T R U C T O R - pointers set on NULL\n");
printf("D E S T R U C T O R - length = %d\n",length);
}

- MAIN -

#include <stdlib.h>
#include <stdio.h>
#include "Queue.h"

void main ()
{
Queue* Q=new Queue();
if((Q->first==NULL)&&(Q->last==NULL)) printf("M A I N - pointers set on NULL\n");
else printf("M A I N - error\n");
printf("M A I N - length = %d\n",Q->length);
delete Q;
if((Q->first==NULL)&&(Q->last==NULL)) printf("M A I N - pointers set on NULL\n");
else printf("M A I N - error\n");
printf("M A I N - length = %d\n",Q->length);
system("pause");
}

- HERE IS WHAT I GET -

M A I N - pointers set on NULL
M A I N - length = 0
D E S T R U C T O R - pointers set on NULL
D E S T R U C T O R - length = 0
M A I N - error
M A I N - length = -17891602

Thx
After you delete Q, you can't attempt to call it's methods or access its members; you deleted it and it may as well not exist anymore. What did you expect to happen after the destructor was called?
aaaaaaaaaaaaaaaaaa
sorry for stupid question, and thx
Topic archived. No new replies allowed.