Hi guys,
The following class keeps giving me a segmentation fault. I am trying to dynamically allocate three pointers ptr1, ptr2, ptr3. Constant Grids is equal to 20. It works if I have only one pointer.
ShuoCode:class matrix_col { public: int i; double *ptr1, *ptr2, *ptr3; matrix_col(){ ptr1 = new double[Grids]; ptr2 = new double[Grids]; ptr3 = new double[Grids]; for(i = 0; i < (Grids); i++) ptr1[i] = 0; ptr2[i] = 0; ptr3[i] = 0; } //copy constructor matrix_col(const matrix_col &a){ int i; ptr1 = new double[Grids]; ptr2 = new double[Grids]; ptr3 = new double[Grids]; for(i = 0; i < (Grids); i++) ptr1[i] = a.ptr1[i]; ptr2[i] = a.ptr2[i]; ptr3[i] = a.ptr3[i]; } ~matrix_col(){ delete [] ptr1; delete [] ptr2; delete [] ptr3; } //double index(int, int); void show_variable(); //void col_insert(flow_field &, flow_field &, flow_field &); friend matrix_col operator+(const matrix_col &, const matrix_col &); friend matrix_col operator-(const matrix_col &, const matrix_col &); const matrix_col &operator=(const matrix_col &); };



LinkBack URL
About LinkBacks


