2011-01-31 4 views
1

J'ai créé une classe et créé une méthode qui initialise toutes les variables.Erreur: Types incompatibles dans l'affectation

sur .h

-(void) initWithX:(float *)x_ andY:(float *)y_ andWidth:(float *)width_; 

et sur .m

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

Lines avec * me donnent erreur "Types incompatibles dans l'affectation", mais je ne comprends pas: je donne 3 flotteurs comme dit dans le .h !!!

Merci à tous

Répondre

5

Passez votre flotte en valeur en retirant la *:

- (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_; 
} 

Sinon, la méthode réclame pointeurs à flotteurs (float *), et non leurs primitives valeurs réelles.

1

vous demandez des pointeurs de flotteur et de les affecter probablement flotter les variables. supprimer les astérisques dans les déclarations de méthode.

Questions connexes