Program received signal: “SIGABRT”.
Nov 7, 2012 at 4:46pm UTC
I just wrote a very simple class.. However, I met some problem..
I want to construct a skip list in c++ and I need to write "node" first. In the node I need to store 4 integers and a string "name"Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
class node{
public :
node **forward;
int x,y,w,h;
string name;
int n; //n is the number of lists the node participates in
//constructor
node (string tempname="unnamed" ,int a=0,int b=0,int c=0,int d=0){
int random=0;
n=0;
while (random<50){
random=rand()%100;
n=n+1;
}
forward= new node*[n];
name=tempname;
x=a;
y=b;
w=c;
h=d;
};
//destuctor
~node (){
delete [] forward;
};
};
And I used to a very simple main() to test it:
1 2 3 4 5 6 7 8 9
int main () {
srand(time(NULL));
node temp1 ("123" ,1,2,3,4);
node temp2;
node temp3;
temp1.~node();
return 0;
}
Then the program received signal "SIGABRT".. I believe the problem is the "temp1.~node()" line...But I just don't know how to fix it....
Are there any one can help me? Thank you so much in advance!
Nov 7, 2012 at 4:49pm UTC
temp1.~node();
Remove this line. You shouldn't be calling the destructor.
Nov 7, 2012 at 6:15pm UTC
Why can't I call the destructor here? Would you please explain that? When is a proper time to call that? Thanks a lot!
Nov 7, 2012 at 7:03pm UTC
When is a proper time to call that?
As a very very good rule of thumb, never.
You don't call the destructor. It gets done for you.
Topic archived. No new replies allowed.