Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

uaecasher

macrumors 65816
Original poster
Jan 29, 2009
1,289
0
Stillwater, OK
hello,

I'm learning Obj-C and i reached where it teach me how to add Methods without argument names so here is my implementation section code:

Code:
//
//  Fraction.m
//  FractionTest
//
//  Created by Fahad Ali on 12/08/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "Fraction.h"


@implementation Fraction

-(void) print {
	NSLog (@"%i/%i", numerator, denominator); 
}

-(double) convertToNum {
	if (denominator != 0) return (double) numerator / denominator;
	else return 1.0;
}

-(void) setTo: (int) n over: (int) d
{
	numerator = n;
	denominator = d;
	
}
- (void) add: (Fraction *) f		

{
	// To add two fractions: // a/b + c/d = ((a*d) + (b*c)) / (b * d)
	numerator = numerator * f.denominator + denominator * f.numerator;
	denominator = denominator * f.denominator;
}

@end

the error is:

error: requests for member 'denominator' in something is not a structure or union
 
Code:
//
//  Fraction.h
//  FractionTest
//
//  Created by Fahad Ali on 12/08/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface Fraction : NSObject {
	
	int numerator;
	int denominator;

}
-(void)		print;
-(void)		setTo: (int) n over: (int) d;
-(void)		add: (Fraction *) f;
-(double)	convertToNum;

@end
 
[CODE

@interface Fraction : NSObject {

int numerator;
int denominator;

}

@property int denominator;
@property int numerator;

-(void) print;
-(void) setTo: (int) n over: (int) d;
-(void) add: (Fraction *) f;
-(double) convertToNum;

@end


@implementaion Fraction

@synthesize denominator;
@synthesize numerator;

....

@end
[/CODE]

Try this.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.