下面代码第45行
#include
using namespace std;
class MyArray
{
public:
MyArray(const int n, const int m)
{
int i, j;
h = n;
l = m;
p = new int *[h];
for (i = 0; i < h; i++)
p[i] = new int[m];
for (i = 0; i < h; i++)
for (j = 0; j < l; j++)
p[i][j] = 0;
}
int *operator[](int s)
{
if (s >= h )
cout << "操作失败......" << endl;
else
return (int*)p[s];
}
~MyArray()
{
cout << "我错了" << endl;
for (int i = 0; i < h; i++)
delete []p[i];
delete []p;
}
private:
int h;
int l;
int **p;
};
int main()
{
MyArray obj(3, 2);
obj[1][1] = 5; //obj[1][2]=5导致数组越界,所以释放的时候出现了意料之外的问题,修正之后就没有问题了
cout << obj[1][1];
cout << endl;
cout << obj[0][0] << endl;
return 0;
}