here is a simple program i am trying to learn Objective-C 2.0. this just has to do with fractions. however, i get an error when i build and run and i haven't figured out how to debug what is wrong. can you spot my error and tell me what it is?
Code:
// First program example
#import <Foundation/Foundation.h>
// ---- @interface section ----
@interface Fraction: NSObject
{
int numerator;
int denominator;
}
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
@end
// ---- @implmentation section ----
@implementation Fraction
-(void) print
{
NSLog (@"%i/%i", numerator, denominator);
}
-(void) setNumerator: (int) n
{
numerator = n;
}
-(void) setDenominator: (int) d
{
denominator = d;
}
@end
// ---- program section ----
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Fraction *myFraction;
// create instance of a Fraction
myFraction = [Fraction alloc];
myFraction = [myFraction init];
// Set fraction to 1/3
[myFraction setNumerator: 1];
[myFraction setDenominator: 3];
// Diplay the fraction using the print method
NSLog (@"The value of myFraction is:");
[myFraction print];
[myFraction release];
[pool drain];
return 0;
}