返回类型为什么不正确啊?

wushuai1346 2009-11-23 01:51:47
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;
}

如题,错误如下:
Improper use of typedef 'couMachine'
Statement missing ;

请大侠帮帮我哈
...全文
143 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wushuai1346 2009-11-24
  • 打赏
  • 举报
回复
谢谢大家,问题已解决
codebm 2009-11-23
  • 打赏
  • 举报
回复
你JAVA过来的吧?c+指针最大 呵呵
wushuai1346 2009-11-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhaojia268115 的回复:]
c++不要直接返回对象,这是java中常用的手段,可以写为:

void getXY(couMachine & temp)

然后在使用的地方定义类对象,当做参数传入函数,利用引用来做这件事!

[/Quote]

不太明白,为什么不可以啊?效率问题还是安全问题,还是不规范什么的,能不能写个Demo看看啊,
zhaojia268115 2009-11-23
  • 打赏
  • 举报
回复
c++不要直接返回对象,这是java中常用的手段,可以写为:

void getXY(couMachine & temp)

然后在使用的地方定义类对象,当做参数传入函数,利用引用来做这件事!
wushuai1346 2009-11-23
  • 打赏
  • 举报
回复
new couMachine(); 
去掉了还是不可以哦
rabbitlzx 2009-11-23
  • 打赏
  • 举报
回复

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;
}
zdeepblue 2009-11-23
  • 打赏
  • 举报
回复

couMachine * getCount=new couMachine(); // new返回的是指针
...
return *getCount;

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧