Obj-C“/先前声明的冲突类型”错误

时间:2011-06-28 22:55:22

标签: objective-c declaration

Obj-C初学者,我在实现文件的以下行中得到“......的冲突类型... /上一个声明......”错误:

-(void) setWidth: (double) w andHeight: (double) h
-(double) area
-(double) perimeter

这是.h和.m:

#import "GraphicObject.h"
#import "XYPOINT.h"  

@interface Rectangle : GraphicObject 

{

    double width;
    double height;
    XYPOINT *origin;

}

@property double width, height;

-(XYPOINT *) origin;
-(void) setOrigin: (XYPOINT *) pt;
-(void) setWidth: (double) w andHeight: (double) h;
-(double) area;
-(double) perimeter;
-(void) translate: (XYPOINT *) v;
-(Rectangle *) intersect: (Rectangle *) r2;
-(void) draw;
-(id) initWithWidth: (double) w andHeight: (double) h;

@end

#import "Rectangle.h"


@implementation Rectangle

@synthesize width, height;

-(void) setWidth: (double) w andHeight: (double) h
{
    width = w;
    height = h;
}

-(double) area
{
    return width * height;
}

-(double) perimeter
{
    return (width + height) * 2;
}

-(void) setOrigin: (XYPOINT *) pt
{
    origin = [[XYPOINT alloc] init];

    [origin setX: pt.x andY: pt.y];
}


-(XYPOINT *) origin
{
    return origin;
}

-(void) translate: (XYPOINT *) v
{
    origin.x += v.x;
    origin.y += v.y;

}

-(Rectangle *) intersect: (Rectangle *) r2

{

    Rectangle *result = [[Rectangle alloc] init];
    XYPOINT *oPoint = [[XYPOINT alloc] init];
    double resultW, resultH, resultX, resultY, deuceX, deuceY;


    resultX = (origin.x > r2.origin.x) ? origin.x : r2.origin.x;
    resultY = (origin.y > r2.origin.y) ? origin.y : r2.origin.y;
    [oPoint setX: resultX andY: resultY];

    deuceX = (origin.x + width < r2.origin.x + r2.width) ? 
    origin.x + width : r2.origin.x + r2.width;

    deuceY = (origin.y + height < r2.origin.y + r2.height) ?
    origin.y + height : r2.origin.y + r2.height;


    resultW = deuceX - resultX;

    resultH = deuceY - resultY;


    if ((resultY >= deuceY) || (resultX >= deuceX)){

        resultW = 0;
        resultH = 0;
        [oPoint setX: 0 andY: 0];
    }




    [result setWidth: resultW andHeight: resultH];
    [result setOrigin: oPoint];

    return result;


}

-(void) draw
{
    for (int h = 0 ; h < height + 2 ; ++h){
        for (int w = 0 ; w < width ; ++w){
            if (h == 0 || h == height + 1){
                printf("-");
            } else {
                if (w == 0 || w == width - 1){
                    printf ("|");
                } else {
                    printf(" ");
                }
            }
        }
        printf("\n");
    }
}

-(Rectangle *) initWithWidth: (double) w andHeight: (double) h

{

    self = [super init];

    if (self)
        [self setWidth: w andHeight: h];

    return self;

}




@end

希望这将是足够的代码来理解问题。

0 个答案:

没有答案