나는 단순한 목록을 만든 다음 그것을 파괴하고있다. 그리고 뭔가 잘못 가고 나는 항상이 짜증나는 오류 메시지가 얻을 :C++ 초보자 : 소멸자
#include<iostream>
#include<Windows.h>
using namespace std;
struct node
{
int data;
node *next;
};
class list
{
protected:
node *top;
public:
list()
{
top=NULL;
}
list random()
{
int x=rand()%10;
for(int i=0; i<x; i++)
{
node *p=new node;
p->data=rand()%100;
p->next=top;
top=p;
}
return *this;
}
void show()
{
for(node *p=top; p; p=p->next)
{
cout<<p->data<<" ";
}
cout<<"\n";
}
~list()
{
node *r;
for(node *p=top; p; p=r)
{
r=p->next;
delete p;
}
}
};
int main()
{
srand(GetTickCount());
list a;
a.random().show();
return 0;
}
[3 가지 규칙] (http://stackoverflow.com/q/4172722/636019)을 위반합니다. – ildjarn