警告:“函数的隐式声明……”在 C99 中无效”
当我尝试比较
.h 文件中两个 UIColors 的 RGB 分量时,我收到此警告,我
-(int) ColorDiff:(UIColor *) color1 :(UIColor *)color2;
在 .m 文件中
- (int) ColorDiff:(UIColor *) color1 :(UIColor *)color2{
... //get RGB components from color1& color2
// compute differences of red, green, and blue values
CGFloat red = red1 - red2;
CGFloat green = green1 - green2;
CGFloat blue = blue1 - blue2;
// return sum of squared differences
return (abs(red) + abs(green) + abs(blue));
}
声明了此内容然后在同一个 .m 文件中,我像这样比较 2 个 UIColors
int d= ColorDiff(C1,C2);// I got the warning right here.
我做了研究,人们说我必须包含头文件。我这样做了,但对我的情况没有帮助。 为什么我会收到此错误?
I'm getting this warning when I'm trying to compare RGB components of two UIColors
In .h file, I declared this
-(int) ColorDiff:(UIColor *) color1 :(UIColor *)color2;
In .m file
- (int) ColorDiff:(UIColor *) color1 :(UIColor *)color2{
... //get RGB components from color1& color2
// compute differences of red, green, and blue values
CGFloat red = red1 - red2;
CGFloat green = green1 - green2;
CGFloat blue = blue1 - blue2;
// return sum of squared differences
return (abs(red) + abs(green) + abs(blue));
}
And then in same .m file, I compare 2 UIColors like this
int d= ColorDiff(C1,C2);// I got the warning right here.
I did research and people say I must include the header file. I did this but didn't help in my case.
Why am I getting this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是因为您将函数定义为实例方法,而不是函数。有两种解决方案。
其中之一是将您的方法声明更改为:
或者,您可以将调用更改为:
It's because you defined your function as a instance method, not a function. There are two solutions.
One of which is this to change your method declaration to this:
Or, you can change your call to this:
.h 文件中的声明与 .m 文件中的实现不匹配。
如果 .m 中方法的实现如下所示:
那么您应该在 .h 中声明它:
并从同一个 .m 文件中调用它,请使用:
The declaration in your .h file doesn't match your implementation in your .m file.
if the implementation of your method in your .m looks like this:
than you should declare it like this in .h:
and to call it from that same .m file, use:
h. 文件中缺少原型!
There is a prototype missing in the h.file!