程序执行不下去,请教原因。
鄙人编写了一个C++程序,当执行到第二次循环时(iy=1)程序就执行不下去了,请教论坛上的高手指出程序问题出在哪?现行谢过!程序如下:
// try0.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<fstream>
#include<cmath>
using namespace std;
int Nx=3;
int Ny=4;
// 动态分配二维指针
class TwoArrayAllocation
{
private:
double** pToDoubleMatrix;
int** pToIntMatrix;
public:
TwoArrayAllocation( );
TwoArrayAllocation(double** pToDouM,int** pToIM);
double** TwoArrayDoubleAlloc(int nRow,int nCol);
int** TwoArrayIntAlloc(int nRow,int nCol);
void DoubleTwoArrayFree(int nRow,double** pT);
void IntTwoArrayFree(int nRow,int** pT);
~TwoArrayAllocation( ){ };
};
TwoArrayAllocation::TwoArrayAllocation( )
{
}
TwoArrayAllocation::TwoArrayAllocation(double** pToDouM,int** pToIM):pToDoubleMatrix(pToDouM),pToIntMatrix(pToIM)
{
}
double** TwoArrayAllocation::TwoArrayDoubleAlloc(int nRow,int nCol)
{
pToDoubleMatrix=new double* [nRow];
if(!pToDoubleMatrix)
{
cout<<"内存分配失败!"<<endl;
exit(-1);
}
for(int j=0;j<nRow;j++)
{
pToDoubleMatrix[j]=new double [nCol];
if(!pToDoubleMatrix)
{
cout<<"内存分配失败!"<<endl;
exit(-1);
}
}
return pToDoubleMatrix;
}
int** TwoArrayAllocation::TwoArrayIntAlloc(int nRow,int nCol)
{
pToIntMatrix=new int* [nRow];
if(!pToIntMatrix)
{
cout<<"内存分配失败!"<<endl;
exit(-1);
}
for(int j=0;j<nRow;j++)
{
pToIntMatrix[j]=new int [nCol];
if(!pToIntMatrix)
{
cout<<"内存分配失败!"<<endl;
exit(-1);
}
}
return pToIntMatrix;
}
void TwoArrayAllocation::DoubleTwoArrayFree(int nRow,double** pToDoubleMatrix)
{
for(int i=0;i<nRow;i++)
delete [] pToDoubleMatrix[i];
delete []pToDoubleMatrix;
}
void TwoArrayAllocation::IntTwoArrayFree(int nRow,int** pToIntMatrix)
{
for(int i=0;i<nRow;i++)
delete [] pToIntMatrix[i];
delete []pToIntMatrix;
}
double ElementalNodeTranfer(double** Lemex,double** Lemey,double** nTran) // 谱单元周界结点按逆时针排列的四个边界单元编号矩阵。
{
int inode(-1);
int i1nod(-1);
int i2nod(-1);
int i3nod(-1);
int i4nod(-1);
for(int iy=0;iy<Ny+1;iy++)
{
for(int ix=0;ix<Nx+1;ix++)
{
inode+=1;
if(iy==0)
{
i1nod+=1;
Lemex[0][i1nod]=inode;
cout<<"Lemex["<<iy<<"]["<<i1nod<<"]="<<inode<<endl;
}
if(ix==Nx)
{
i2nod+=1;
Lemey[0][i2nod]=inode;
cout<<"Lemey["<<ix<<"]["<<i2nod<<"]="<<inode<<endl;
}
if(iy==Ny)
{
i3nod+=1;
Lemex[1][Nx-i3nod]=inode;
cout<<"Lemex["<<iy<<"]["<<Nx-i3nod<<"]="<<inode<<endl;
}
if(ix==0)
{
i4nod+=1;
Lemey[1][Ny-i4nod]=inode;
cout<<"Lemey["<<ix<<"]["<<Ny-i4nod<<"]="<<inode<<endl;
}
nTran[ix][iy]=inode;
cout<<"nTran["<<ix<<"]["<<iy<<"]="<<nTran[ix][iy]<<endl;
}
}
return(0);
}
int _tmain(int argc, _TCHAR* argv[])
{
int i,j;
double** Lemex;
double** Lemey;
double** nTran;
TwoArrayAllocation pT;
Lemex=pT.TwoArrayDoubleAlloc(2,3);
Lemey=pT.TwoArrayDoubleAlloc(2,4);
nTran=pT.TwoArrayDoubleAlloc(3,4);
ElementalNodeTranfer(Lemex,Lemey,nTran);
pT.DoubleTwoArrayFree(2,Lemex);
pT.DoubleTwoArrayFree(2,Lemey);
pT.DoubleTwoArrayFree(3,nTran);
return 0;
}