There are two way, I make a difference, is this okey? #include <iostream> class Matrix { private: double** array; int row, column; public: Matrix(int m, int n) { this->row=m; this->column=n; this->array = new double*[m]; for (int i = 0; i < n; i++){ this->array[i] = new double[n]; std::fill(array[i],array[i]+n,0.0); } } Matrix(Matrix &matrix){ this->array=matrix.array; this->row=matrix.row; this->column=matrix.column; } Matrix& operator=(const Matrix& rhs ){ this->row=rhs.row; this->column=rhs.column; for(int i=0;i<row;++i) for(int j=0;j<column;++j) this->array[i][j]=rhs.array[i][j]; } ~Matrix() { for (int i = 0; i < this->row; i++) delete[] this->array[i]; delete[] this->array; } void print(){ for(int i=0;i<this->row;++i){ for(int j=0;j<this->column;++j) printf("%f\t",this->array[i][j]); printf("\n"); } } double * operator [](int m){ return this->array[m]; } }; int main(int argc, const char * argv[]) { Matrix A(2,2); A[0][1]=1; A[0][0]=0; A[1][0]=1; A[1][1]=1; A.print(); return 0; } ---------- Using Vector, is it okey? #include <iostream> #include <vector> using namespace std; class Matrix { private: vector< vector<double> > array; int row, column; public: Matrix(int m, int n) { row = m; column = n; array = vector< vector<double> > (m, vector<double> (n, 0)); } Matrix(Matrix &matrix){ this->array=matrix.array; this->row=matrix.row; this->column=matrix.column; } void print(){ for(int i=0;i<this->row;++i){ for(int j=0;j<this->column;++j) printf("%f\t",this->array[i][j]); printf("\n"); } } vector<double> & operator [](int m){ return this->array[m]; } }; ----------- I would like to make a `Matrix` class in cpp. Can any of you help me about this class? #include <iostream> using namespace std; class matrix { int **p, m, n; public: matrix(int row, int col) { m = row; n = col; p = new int*[m]; for (int i = 0; i < m; ++i) { p[i] = new int[n]; for (int j = 0; j < n; ++j) p[i][j] = 0; } } ~matrix() { for(int i=0;i<m;++i) delete [] p[i]; delete [] p; } void accept() { cout<<"Enter matrix elements: "; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { cin >> p[i][j]; } } } void display() { cout <<"The matrix is:\n"; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { cout << p[i][j] <<" "; } cout <<endl; } } matrix& operator+ (const matrix& m1) { return (*this += m1); } matrix& operator* (const matrix& m1) { return (*this *= m1); } matrix& operator+= (const matrix& rhs) { for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { p[i][j] += rhs.p[i][j]; } } return *this; } matrix& operator*= (const matrix& T) { if(n == T.m) { for(int i = 0; i < T.m; ++i) { for(int k = 0; k < n; ++k) { p[i][k] *= T.p[k][i]; } } } return *this; } matrix& operator= (const matrix& T) { p = T.p; n = T.n; m = T.m; return *this; } }; int main() { matrix rf(3,3), ff(3,3); rf.accept(); cout << "\nrf\n"; rf.display(); ff.accept(); cout << "\nff\n"; ff.display(); cout << "\nff = ff + rf\n"; ff = ff + rf; ff.display(); cout << "\nff = (rf * ff)\n"; ff = (rf * ff); ff.display(); cout << "\nrf += ff\n"; rf += ff; rf.display(); }