开发者

Obj-C "Conflicting types for/ Previous declaration of" errors

开发者 https://www.devze.com 2023-03-16 05:19 出处:网络
Obj-C beginner, I\'m getting \"Conflicting types for.../ Previous declaration of...\" errors on the following lines of the implementation file:

Obj-C beginner, I'm getting "Conflicting types for.../ Previous declaration of..." errors on the following lines of the implementation file:

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

Here's the .h and .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 ==开发者_如何学JAVA 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

Hopefully that will be enough code to understand the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号