c++ - Array of objects not working correctly -
i have class creates array of objects class(the array class friend)
class vector_xxl { int i=0,n=0; xxl_nr *xxlvector; public: vector_xxl(int y) { n = y; xxlvector = new xxl_nr[y];}
n size of array. xxl_nr class creates large numbers represented linked list(each digit has spot on list)
i want product of each 2 numbers 2 array objects on same positions. so, example, v[i]*d[i] , = 0,n;
this function should doesn't work correctly:
void produs_scalar(vector_xxl a) { xxl_nr temp(2),temp1(2),temp2(2),result(2); vector_xxl vector_result(n); temp1 = this->xxlvector[0]; temp2 = a.xxlvector[0]; temp1.addition(temp2); for(i=0;i<n;i++) { temp = this->xxlvector[i].product(a.xxlvector[i]); vector_result.xxlvector[i] = temp; } for(i=0;i<n;i++) result= temp.product(vector_result.xxlvector[i]); result.print(); }
i used temp1, , temp2 test if can use product method(defined in class xxl_nr) on 2 xxl_nr variables. result same. problem is, in first loop, product, returns correct answer `this->xxlvector[i].product(a.xxlvector[i]); not move i-th position, entire program hangs there after product method returns. now, believe array problem, because tried doing product without using array(just xxl_nr types) , method doesn't hang anymore. example:
void produs_scalar()//vector_xxl &a) { xxl_nr b(2), c(2), d; cout<<"insert number b"; cin>> b; cout<<"number c"; cin>>c; d=b.product(c); cout<<d;
here, works fine. product methos returns, , code adcances cout<<d;
.
i read on 1 topic when program hangs it's because of pointing random memory , program hangs, have no idea how debug or how verify if that's case.
the assignment 'temp' product incorrect. in array demonstration assign result of 'product' type xxl_nr(2) while in example no arrays assigning result type xxl_nr. without code xxl_nr unclear type being created.
Comments
Post a Comment