Ошибка: нет декларации собственности - PullRequest
0 голосов
/ 13 января 2011

У меня есть два свойства, которые я объявляю в своем заголовочном файле и синтезирую в своем файле класса (имя?):

  • ширина
  • высота

    (символ хеш / фунт) импорт

    @interface Rectangle : NSObject {   int width;  int height; }
    
    @property width, height;
    
    -(int) area;
    -(int) perimeter;
    -(void) setWidth: (int) w setHeight: (int) h;
    
    @end
    

.m файл:

 (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

Однако я получаю некоторые ошибки:

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;

Прошу прощения за форматирование У меня проблемы с символом # и форматированием кода.

Ответы [ 2 ]

3 голосов
/ 13 января 2011

Я удивлен ...

@property width, height;

... что даже компилируется.Это должно быть:

@property int width;
@property int height;

И вы почти никогда не увидите этого:

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

Вместо @property подразумеваются setWidth: и setHeight:.

2 голосов
/ 13 января 2011

Попробуйте это:

@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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...