Incomplete implementation (xcode error?)

//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

In the final line, @endXcode tells me that the implementation is incomplete. The code still works as expected, but I'm new to this, and I'm worried that something was missing. As far as I can tell, it is full. Sometimes it seems to me that Xcode depends on past errors, but maybe I'm just going crazy!

Thank! -Andrew

+5
source share
1 answer

In 9.1.hyou missed 'a'.

-(void) setReal: (double) andImaginary: (double) b;
//                       ^ here

The code is still valid because in Objective-C, the selector part cannot have any name, for example

-(id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y
//                                    ^           ^           ^

these methods are called

return [self initWithControlPoints:0.0f :0.0f :1.0f :1.0f];
//                                      ^     ^     ^

and the name of the selector is natural @selector(initWithControlPoints::::).

Therefore, the compiler will interpret your declaration as

-(void)setReal:(double)andImaginary
              :(double)b;

-setReal::, gcc

warning: incomplete implementation of class ‘Complex’
warning: method definition for ‘-setReal::’ not found

BTW, , , Objective-C, C99 complex, ,

#include <complex.h>

...

double complex z = 5 + 6I;
double complex w = -4 + 2I;
z = z + w;
printf("%g + %gi\n", creal(z), cimag(z));
+10

All Articles