Hi I have the following class called CalculatorOperations:
#import "CalculatorOperations.h"
@implementation CalculatorOperations
+(float)add:(float)numOne with:(float)numTwo{
return numOne + numTwo;
}
@end
I then try to call this class method as follows from within my Calculator class:
#import "Calculator.h"
#import "CalculatorOperations.h"
#import <Foundation/Foundation.h>
@implementation Calculator
+(float)add:(float)numOne to:(float)numTwo{
CalculatorOperations *calcOp = [CalculatorOperations alloc];
float answer = [calcOp add:numOne with:numTwo];
return answer;
}
@end
The problem is I keep getting a “incompatible types in initialisation” message when trying to assign the return value of a the add:with method to a variable (answer).
Why is this?
You shouldn’t be calling a class method (the
+indicates class method) on an instance of the class. In addition, you aren’tiniting the class as required for an instance of that class.Try this: