hello, I'm learning Objective-C from the book "Programming in Objective-C 2.0".
Now i don't know if this is intentional or not but this book got hell of typos, so I'm in the inheritance chapter and trying to run this example but i keep getting this error message:
'Rectangle' may not respond to "-setWidth:andHeight:'
here is my code:
header file (Rectangle.h):
implementation file (rec.m) :
main.m
the error appears at:
Now i don't know if this is intentional or not but this book got hell of typos, so I'm in the inheritance chapter and trying to run this example but i keep getting this error message:
'Rectangle' may not respond to "-setWidth:andHeight:'
here is my code:
header file (Rectangle.h):
Code:
@interface Rectangle: NSObject
{
int width;
int height;
}
@property int width, height;
-(int) area;
-(int) perimeter;
@end
implementation file (rec.m) :
Code:
//
// rec.m
// inher
//
// Created by Fahad Ali on 9/22/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "Rectangle.h"
@implementation Rectangle
@synthesize width, height;
-(void) setWidth: (int) w andHeight: (int) h;
{
width = w;
height = h;
}
-(int) area
{
return width * height;
}
-(int) perimeter
{
return (width + height) * 2;
}
@end
main.m
Code:
#import "Rectangle.h"
#import <stdio.h>
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Rectangle *myRect = [[Rectangle alloc] init];
[myRect setWidth:5 andHeight:8];
NSLog (@"w = %i, h = %i",
myRect.width, myRect.height);
NSLog (@"Area = %i, Perimeter = %i",
[myRect area], [myRect perimeter]);
[myRect release];
[pool drain];
return 0;
}
the error appears at:
Code:
[myRect setWidth:5 andHeight:8];