二维数组类关于深拷贝
class Arrary
{public:
Arrary(int m=5,int n=6,int value=0)
{
arrary=new int*[m];
for(int i=0;i<m;i++)
{arrary[i]=new int[n];
}
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
*(*(arrary+i)+j)=value;
}
Arrary( Arrary &other)
{this->~Arrary();
printf("copy");
for(int i=0;i<other.m;i++)
{arrary[i]=new int[n];
}
for(int i=0;i<other.m;i++)
for(int j=0;j<other.n;j++)
{ *(*(arrary+i)+j)=other.arrary[i][j];
printf("%d",other.arrary[i][j]); }
m=other.m;
n=other.n;
}
~Arrary()
{for(int i=0;i<m;i++)
delete[] arrary[i];
delete[] arrary;
}
int GetValue(int m,int n)
{if( m<0 || m>this->m || n<0 || n>this->n)
{printf("访问不存在的元素!");
return 0;}
else
{return arrary[m][n];}
}
int SetValue(int m,int n)
{}
private:
int m,n;
int **arrary;
};
using namespace std;
void test(Arrary a)
{cout<<"test:"<<a.GetValue(4,4)<<endl;}
int main(){
Arrary a(5,5,4),b;
b=a;
//test(a);
cout<<b.GetValue(4,4);
system("pause");
return 0;
}
==================
我写的深拷贝函数有错吗?为什么运行的时候会出错啊。。