Reputation: 142
I've been on this for hours and can't find a solution. When I try to compile the following I get the "Incompatible types in initialization" error on the marked lines. Any help is accepted.
Here's my Controller.m file:
#import "Controller.h"
#import "Transactions.h"
@implementation Controller
- (IBAction)add:(id)sender {
double x = [addF doubleValue];
double bal = [balanceF doubleValue];
double newBal = [trans add:x to:bal]; //Error marked here
[balanceF setDoubleValue:newBal];
}
- (IBAction)sub:(id)sender {
double x = [subF doubleValue];
double bal = [balanceF doubleValue];
double newBal = [trans sub:x from:bal]; //Error marked here
[balanceF setDoubleValue:newBal];
}
@end
And here's my Transactions.m file:
#import "Transactions.h"
@implementation trans
-(double) add:(double)x to:(double)bal{
return (x + bal);
}
-(double) sub:(double)x from:(double)bal{
return (bal - x);
}
@end
Please tell me if you need anything else. Thanks!
Upvotes: 1
Views: 216
Reputation: 137272
'trans' is a class, so if you declare / call method using the class, and not an instance of it, they should be declared with +
:
+(double) add:(double)x to:(double)bal{
+(double) sub:(double)x from:(double)bal{
Don't forget to change in the header file as well...
Upvotes: 1