不兼容的类型分配
问题描述:
四处错误:在F值= ...不兼容的类型分配,看到代码不兼容的类型分配
static float t = 0;
float d = .5;
static float fValue = 0;
fValue = [self easeOutBounce:t andB:0 andC:30 andD:d];
这里是方法
-(float) easeOutBounce:(float)t andB:(float)b andC:(float)c andD:(float)d {
if ((t/d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-(2.625/2.75))*t + .984375) + b;
}
}
答
当编译器遇到未知方法(即正在使用但尚未在@interface
中声明的方法,或之前在@implementation
中定义的方法),编译器将发出警告,并假定该方法返回id
,这是一种指针类型,您可以'分配给一个float
类型。
确保您@interface
有声明的easeOutBounce:andB:andC:andD:
方法,或者,至少是,确保这种方法上面定义使用它的代码。
例如:
@interface MyClass : NSObject
{
float myVar;
}
-(float) easeOutBounce:(float)t andB:(float)b andC:(float)c andD:(float)d;
@end
不知道它是否有关,但不是你在过去的2个return语句缺少一个“*”? – 2010-06-03 07:22:37
该类的'@ interface'声明是否包含'easeOutBounce:andB:andC:andD:'方法? – dreamlax 2010-06-03 07:29:08
请发布有问题的文件的完整编译器输出。我最好的猜测是你错过了一些其他的警告,例如,编译器没有看到方法声明,所以它已经假定它返回id。 – 2010-06-03 07:30:33