c++ - Why is this function segfaulting? -


the function this:

set::set(multinumber* temparray[], int tempsize) {  numelements = tempsize;  capacity = tempsize*2;  setarray = new multinumber*[capacity];  (int i=0; i<numelements; i++)  {   addelement(temparray[i]);  } } 

the variable setarray declared in header of type multinumber**

it segfaults whenever call this:

multinumber* carr[2]; carr[0]=c4; carr[1]=c5; set setb(carr,2); 

c4 , c5 declared pointers objects of proper type.

any appreciated.

edit: code below addelement function (apologies indentation)

const set set::operator+(const set& rhs) const {  set result;  int i=0, j=0;   while ((i < numelements) && (j < rhs.numelements))  {   multinumber* toadd=new multinumber;   toadd=*(setarray[i]) + *(rhs.setarray[j]);   result.addelement(toadd);   i++;   j++;  }   while ((i < numelements))  {   result.addelement(setarray[i]);   i++;  }     while ((j < rhs.numelements))  {  result.addelement(rhs.setarray[j]);  j++;  }    return result; } 

edit: based on numerous cout statements, error seems in function:

 bool set::isfull()  {   return (numelements == capacity);  } 

edit: changed array indices, still segfaults

carr[1]=c4; carr[2]=c5; 

shouldn't be

carr[0]=c4; carr[1]=c5; 

?

piece of advice: if load in debugger, such gdb, have identified culprit line , would've seen error quickly.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -