函数“...”的隐式声明在C99中无效?

时间:2013-07-22 05:11:19

标签: objective-c function-calls

我正在尝试在另一个函数中声明一个函数。所以这是我的代码的一部分: ViewController.m

- (void)updatedisplay{
    [_displayText setText:[NSString stringWithFormat:@"%d", counter]];

}

- (IBAction)minus1:(id)sender {
    counter--;
    updatedisplay();
}

ViewController.h

- (IBAction)minus1:(id)sender;
- (void)updatedisplay;

其中返回了“隐式声明功能”的错误......“在C99中无效”。

结果:http://i.imgur.com/rsIt6r2.png

我发现人们遇到过类似的问题,但作为一个新手,我真的不知道接下来该做什么。谢谢你的帮助! :)

Implicit declaration of function '...' is invalid on C99

4 个答案:

答案 0 :(得分:10)

你没有声明function;但是要instance method,所以要将其作为消息发送给self;

[self updatedisplay];

修改

正如@rmaddy指出的那样(感谢),它被声明为实例方法而不是类方法。使事情清楚;

- (return_type)instance_method_name....通过'self'或指向对象实例的指针调用  + (return_type)class_method_name....直接在类上调用(静态)。

答案 1 :(得分:5)

问题

updatedisplay();

解决方案

[self updatedisplay];

原因

- (void)updatedisplay;

是可用于该类的类方法。因此,您必须从类中调用以使该方法可用。

答案 2 :(得分:3)

这是因为您将函数定义为实例方法,而不是函数。

所以像

一样使用它
- (IBAction)minus1:(id)sender {
    counter--;
    [self updatedisplay]; // Change this line
}

答案 3 :(得分:2)

这样写:

[self updatedisplay];