33,311
社区成员
发帖
与我相关
我的任务
分享
class couMachine
{
public:
int x;
int y;
};
couMachine getXY()
{
couMachine getCount=new couMachine();
for(int i=0;i<7;i++)
{
bool isContinue=1;
for(int j=0;j<8;j++)
{
int t=0;
t= Arry_temp[i][j];
Arry_temp[i][j]=Arry_temp[i][j+1];
Arry_temp[i][j+1]=t;
if(getTF(Arry_temp,i,j))
{
getCount.x=i;
getCount.y=j;
isContinue=0;
return;
}
if(isContinue==0)
return;
}
if(isContinue==0)
return;
}
return getCount;
}
new couMachine();
去掉了还是不可以哦
couMachine getXY()
{
couMachine getCount=new couMachine(); //错误在这句,new生成的是couMachine对象的指针
//可以改为
couMachine getCount;
for(int i=0;i<7;i++)
{
bool isContinue=1;
for(int j=0;j<8;j++)
{
int t=0;
t= Arry_temp[i][j];
Arry_temp[i][j]=Arry_temp[i][j+1];
Arry_temp[i][j+1]=t;
if(getTF(Arry_temp,i,j))
{
getCount.x=i;
getCount.y=j;
isContinue=0;
return;
}
if(isContinue==0)
return;
}
if(isContinue==0)
return;
}
return getCount;
}
couMachine * getCount=new couMachine(); // new返回的是指针
...
return *getCount;