问题 如何在Objective C中解决警告隐式声明函数


日志

warning: implicit declaration of function 'TutorialAlertWithMessageAndDelegate'

这是我的代码

.h

void TutorialAlertWithMessageAndDelegate(NSString *title, NSString *message, id delegate);


.m
void TutorialAlertWithMessageAndDelegate(NSString *title, NSString *message, id delegate)
{
    /* open an alert with OK and Cancel buttons */
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title 
                                                    message:message
                                                   delegate:delegate 
                                          cancelButtonTitle:@"Dismiss"
                                          otherButtonTitles: @"Show Tutorial", @"Disable Tutorial", nil];
    // otherButtonTitles: @"Show Next Tip", @"Disable Tips", nil];
    [alert show];
    [alert release];
}

4772
2018-02-13 05:10


起源

我需要生成该警告的代码,而不是定义函数的代码:这就是问题所在。 - Grant Paul


答案:


当您在声明函数之前尝试调用函数时会生成该警告。标题(.h)文件中的声明似乎是正确的,但您可能不会在调用该函数的源文件中包含该头文件。一定要放:

#include "Tutorial.h" // replace with actual filename, of course

在该源文件的顶部。


12
2018-02-13 05:16



谢谢,我忘记了它,但为什么它也有效? - RAGOpoR
C不要求您声明函数,尽管这样做是最佳实践。这就是为什么它只给你一个警告,而不是一个错误。 - benzado
谢谢你benzado ^ _ ^ - RAGOpoR