redconservatory
redconservatory

Reputation: 21924

Error: no declaration of property

I have two properties I declare in my header file and synthesize in my class (name?) file:

.m file:

 (hash/pound symbol)import "Rectangle.h"
@implementation Rectangle

@synthesize width, height;
-(void) setWidth: (int) w setHeight: (int) h
{
    width = w;
    height = h;
}
-(int) area
{
    return width * height;
}
-(int) perimeter
{
    return (width + height) * 2;
}
@end

However, I am getting some errors:

error: syntax error before 'width;
error: no declaration of property 'width' found in the interface;
error: no declaration of property 'height' found in the interface;

Please excuse the formatting I am having problems with the '#' symbol and the code formatting.

Upvotes: 0

Views: 236

Answers (2)

Stephen Furlani
Stephen Furlani

Reputation: 6856

Try this:

@interface Rectangle : NSObject 
{   
  int width;  
  int height; 
}

@property int width;
@property int height;

-(int) area;
-(int) perimeter;
-(void) setWidth: (int) w andHeight: (int) h;

@end

Upvotes: 2

bbum
bbum

Reputation: 162712

I'm surprised...

@property width, height;

... that even compiles. It should be:

@property int width;
@property int height;

And you'd almost never see this:

-(void) setWidth: (int) w setHeight: (int) h;

Instead, the @property implies setWidth: and setHeight:.

Upvotes: 3

Related Questions