Xcode中应有表达式错误
Expected Expression Error in Xcode
我正在为一个游戏制作移动函数,但我得到了一个预期的表达式错误,我不知道为什么,我所做的似乎是合法的。
void Ant::move()
{
int dir=rand()%4;
if (dir==0)
{
if ((y>0) && (world->getAt(x,y-1)==NULL))
{
world->setAt(x,y-1,world->getAt(x,y));
world->setAt(x,y,NULL);
y++;
}
}
else
{
if ((x<WORLDSIZE-1) && (world->getAt(x+1,y)==NULL))
{
world->setAt(x-1,y,world->getAt(x,y));
world->setAt(x,y,NULL);
x--;
}
}
else
{
if ((x<WORLDSIZE-1) && (world-getAt(x+1,y)==NULL))
{
world->setAt(x+1,y,world->getAt(x,y));
world->setAt(x,y,NULL);
x++;
}
}
}
问题出在第二个电话上。
我认为问题是:
world-getAt(x+1,y)==NULL
您忘记了>
world->getAt(x+1,y)==NULL
在第二个if语句中。
在第一个else之后缺少if
。你现在有
if {
...
} else { // here you need an if - or revise the structure
} else {
}
例如,试试。。。
void Ant::move()
{
int dir=rand()%4;
if (dir==0)
{
if ((y>0) && (world->getAt(x,y-1)==NULL))
{
world->setAt(x,y-1,world->getAt(x,y));
world->setAt(x,y,NULL);
y++;
} else
if ((x<WORLDSIZE-1) && (world->getAt(x+1,y)==NULL))
{
world->setAt(x-1,y,world->getAt(x,y));
world->setAt(x,y,NULL);
x--;
} else
if ((x<WORLDSIZE-1) && (world-getAt(x+1,y)==NULL))
{
world->setAt(x+1,y,world->getAt(x,y));
world->setAt(x,y,NULL);
x++;
}
}
}
相关文章:
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- C++ 标记之前预期主表达式'('错误
- 正则表达式中带有卷轴大括号的正则表达式错误
- C++初学者错误:主要表达式错误
- 代数树表达式C++错误:未解析的外部符号"Public:_thiscall AlgebraicTreeExpression::~AlgebraicTreeExpression(void) ..."
- 使用多线程处理对象数组 - 无效使用 void 表达式错误
- 为什么 if constexpr 不会使这个核心常量表达式错误消失?
- 提升正则表达式错误:未初始化的提升::match_results
- C++比较表达式错误
- C++ "主表达式"错误
- C++ 正则表达式错误(未处理的异常)
- 'this'不能用于常量表达式错误 (C++)
- 代码块引发有关for_each的预期主表达式错误
- Boost Regex中的命名子表达式错误
- C++之前的主要表达式错误
- Ubuntu 上的正则表达式错误
- C++正则表达式错误
- 理解常量表达式错误
- 成员函数和预期的主表达式错误
- Xcode中应有表达式错误