123456789101112131415161718192021222324252627282930313233343536
class Matrix{ public: Matrix(int the_h, int the_w){ h=the_h; w=the_w; matrix=new float*[h]; for(int i=0;i<h;i++) matrix[i]=new float[w];//create 2d for(int i=0;i<h;i++) for(int j=0;j<w;j++) matrix[i][j]=0;//init 2d all to 0 } ~Matrix(){ for(int i=0;i<h;i++) delete [] matrix[i];//delete 2d delete [] matrix; } float** getMatrix(){return matrix;} Matrix& operator+(Matrix &the_matrix){ Matrix sol(h,w); for(int i=0;i<h;i++) for(int j=0;j<w;j++) //some operation return sol;//calls delete here, return garbage } private: int h, w; float **matrix; };
warning C4172: returning address of local variable or temporary