oop - Segmentation fault when creating object c++ -
i have class in c++, has constructor in matrix.h:
private: int col; int row; bool isvalid; int **matrix; public: matrix(int inputint);
and in matrix.cpp file :
matrix::matrix(int inputint) { row=inputint; col=inputint; (int i=0;i<row;i++) matrix[i]=new int [col]; (int i=0;i<row;i++) (int j=0;j<col;j++) matrix[i][j]=0; isvalid=true; }
and in main.cpp wrote
matrix a(3);
and got segmentation fault. why ?
matrix
pointer pointer, need new
matrix
@ first.
matrix::matrix(int inputint) { row=inputint; col=inputint; matrix = new int* [row]; (int i=0;i<row;i++) matrix[i]=new int [col]; (int i=0;i<row;i++) (int j=0;j<col;j++) matrix[i][j]=0; isvalid=true; }
Comments
Post a Comment