// 9.1.h
#import <Foundation/Foundation.h>
@interface Complex : NSObject
{
double real;
double imaginary;
}
@property double real, imaginary;
-(void) print;
-(void) setReal: (double) andImaginary: (double) b;
-(Complex *) add: (Complex *) f;
@end
#import "9.1.h"
@implementation Complex
@synthesize real, imaginary;
-(void) print
{
NSLog(@ "%g + %gi ", real, imaginary);
}
-(void) setReal: (double) a andImaginary: (double) b
{
real = a;
imaginary = b;
}
-(Complex *) add: (Complex *) f
{
Complex *result = [[Complex alloc] init];
[result setReal: real + [f real] andImaginary: imaginary + [f imaginary]];
return result;
}
@end
On the final @end line, Xcode is telling me the implementation is incomplete. The code still works as expected, but I’m new at this and am worried I’ve missed something. It is complete as far as I can tell. Sometimes I feel like Xcode hangs on to past errors, but maybe I’m just losing my mind!
Thanks!
-Andrew
In
9.1.h, you have missed an ‘a’.The code is still valid, because in Objective-C a selector’s part can have no name, e.g.
these methods are called as
and the selector name is naturally
@selector(initWithControlPoints::::).Therefore, the compiler will interpret your declaration as
since you have not provided the implementation of this
-setReal::method, gcc will warn you aboutBTW, if you just want a complex value but doesn’t need it to be an Objective-C class, there is C99 complex, e.g.