Objective c 错误:分配中存在不兼容的类型

Objective c 错误:分配中存在不兼容的类型,objective-c,floating-point,init,Objective C,Floating Point,Init,我构建了一个类并创建了一个初始化所有变量的方法 on.h 等等 -(void) initWithX:(float *)x_ andY:(float *)y_ andWidth:(float *)width_{ [super init]; x = x_; *** y = y_; *** width = width_; *** } 带*的行在赋值中给了我错误不兼容的类型,但我不明白:我给了3个浮动,如.h中所述 谢谢大家您正在请求浮点指针,并可能将它们分

我构建了一个类并创建了一个初始化所有变量的方法

on.h

等等

    -(void) initWithX:(float *)x_ andY:(float *)y_ andWidth:(float *)width_{
    [super init];
    x = x_;  ***
    y = y_;  ***
    width = width_; ***
}
带*的行在赋值中给了我错误不兼容的类型,但我不明白:我给了3个浮动,如.h中所述


谢谢大家

您正在请求浮点指针,并可能将它们分配给浮点变量。去掉方法声明中的星号。

您正在请求浮点指针,并可能将它们分配给浮点变量。去掉方法声明中的星号。

通过删除*,按值传递浮点数:


否则,该方法将请求指向浮点浮点*的指针,而不是它们的实际基元值。

通过删除*,按值传递浮点:

否则,该方法将请求指向float*的指针,而不是它们的实际原语值

    -(void) initWithX:(float *)x_ andY:(float *)y_ andWidth:(float *)width_{
    [super init];
    x = x_;  ***
    y = y_;  ***
    width = width_; ***
}
- (void)initWithX:(float)x_ andY:(float)y_ andWidth:(float)width_;

- (void)initWithX:(float)x_ andY:(float)y_ andWidth:(float)width_ {
    [super init];
    x = x_;
    y = y_;
    width = width_;
}