Objective c ';预期表达式';错误

Objective c ';预期表达式';错误,objective-c,compiler-errors,Objective C,Compiler Errors,我在以下代码中收到预期的表达式错误: (void) for(t; t < kPlatformsStartTag + kNumPlatforms; t++) { //error here CCSprite *platform = (CCSprite*)[batchNode getChildByTag:t]; CGSize platform_size = platform.contentSize; CGPoint platform_pos = platform.position; ma

我在以下代码中收到预期的表达式错误:

 (void) for(t; t < kPlatformsStartTag + kNumPlatforms; t++) { //error here
 CCSprite *platform = (CCSprite*)[batchNode getChildByTag:t];

CGSize platform_size = platform.contentSize;
CGPoint platform_pos = platform.position;

max_x = platform_pos.x - platform_size.width/2 - 10;
min_x = platform_pos.x + platform_size.width/2 + 10;
float min_y = platform_pos.y + (platform_size.height+bird_size.height)/2 - kPlatformTopPadding;

if(bird_pos.x > max_x &&
   bird_pos.x < min_x &&
   bird_pos.y > platform_pos.y &&
   bird_pos.y < min_y) {
    [self jump];
    }
}

 (void) for(t; t < kCloudsStartTag + kNumClouds; t++) { //error here
CCSprite *cloud = (CCSprite*)[batchNode getChildByTag:t];
CGPoint pos = cloud.position;
pos.y -= delta * cloud.scaleY * 0.8f;
if(pos.y < -cloud.contentSize.height/2) {
currentCloudTag = t;
     [self resetCloud];
} else {
    cloud.position = pos;
    }
}
(t;t最大位置x&& 鸟的位置x<最小位置x&& 鸟类位置y>平台位置y&& 鸟(位置y<最小y){ [自跳]; } } (void)对于(t;t
在“for”代码所在的位置发现错误。我放入了(void)代码,因为我将得到一个表达式结果unused error。有什么想法吗?

for循环之前的
(void)
没有意义。

您必须删除
(void)
for循环之前的
,因为它不是有效的c语法。你不能用另一个错误来解决一个错误

您可能会问这样一个问题:为什么在
for
循环之前放置
(void)
,可以防止未使用的表达式错误。那是因为调试器没有找到它。而且它不知道什么是
,因为他期望从中得到一个结果值,将其转换为无效

编译器生成错误时:
未使用的实体问题-表达式结果未使用
。这意味着您的程序正在计算表达式而不使用它

for
循环中,如果
t
变量已按您的要求初始化,则不应将其放在第一部分,因为它将被视为未使用的表达式

for(; t < kPlatformsStartTag + kNumPlatforms; t++) { // keep the first expresion empty
    // ...
}
for(;t
您已经得到了关于伪
(void)
的答案,但没有得到关于未使用表达式的答案

for(; t < kPlatformsStartTag + kNumPlatforms; t++) { // keep the first expresion empty
    // ...
}
虽然就我个人而言,我可能倾向于使用
while
循环

编辑:更仔细地阅读代码,您的代码似乎需要给
t
一个初始值

for(t = 0; t < kCloudsStartTag + kNumClouds; t++)
for(t=0;t

无论哪种方式,您试图在不了解警告内容的情况下抑制警告都不是一个好主意。

生成的错误到底是什么?在
的之前没有无效的错误?这与Xcode无关。另外,学习C的基础知识(可能使用书籍或教程)。你必须了解语言的基本要素,我们不是来给你灌输这些要素的。@H2CO3-谢谢你的建议,这些建议对我的问题没有帮助。我在xcode引擎上使用objective-C。@rullof-我在没有void的情况下得到的错误是未使用的实体问题-表达式结果未使用。我从这一页得到了无效的解决方案:我认为,user2984757并不是因为未使用的变量而谈论警告,而是因为表达式的未使用结果(例如,调用函数返回
int
,而不使用其结果)。在我看来,这是一个毫无用处的警告,因为在C语言中,几乎每个表达式都包含一个只对其副作用进行评估的表达式(
x=y;
有一个未使用的结果,例如,编写
(void)(x=y)
是愚蠢的),忽略非void表达式的结果通常没有什么错。@mafso我只是错过了它,因为他没有解决问题。没有void的错误是未使用的实体问题-表达式结果未使用。我从这一页上得到了无效的解决方案:谢谢,成功了。
for(t = 0; t < kCloudsStartTag + kNumClouds; t++)