1 class Matrix{ 2 public: 3 Matrix(int dimM, int dimN){ //构造函数 4 a = new double *[dimM]; 5 int i = 0; 6 for(i = 0; i < dimM; i++){ 7 a[i] = new double[dimN]; 8 } 9 } 10 11 ~Matrix(){ 12 for (int i = 0; i<M; i++) 13 delete []a[i]; 14 delete []a; 15 } 16 17 void input(int m, int n); 18 void output(int m, int n); 19 Matrix (const Matrix & copy); 20 21 private: 22 int M; 23 int N; 24 double **a; 25 26 }; 27
我建立Matrix的类,在main函数中,定义一个类m1(2,3),调用m1.input、m1.output函数输出;然后调用拷贝构造函数,Matrix m2(m1), 调用m2.output,编译通过,执行错误,提示析构函数两次被调用,core dumped,求大神指点,哪个地方错了
析构函数定义了两次delete
不是吧