problem (einfach mal lesen):
------------------------complex.h
#import <objc/Object.h>
@interface Complex : Object
{
double real;
double imaginary;
}
-(void) setReal: (double) a;
-(void) setImaginary: (double) b;
-(void) setReal: (double) a andImaginary: (double) b;
-(double) getReal;
-(double) getImaginary;
-(Complex *) add: (Complex *) f;
-(void) print;
@end
------------------------------complex.m
#import "Complex.h"
@implementation Complex
-(void) setReal: (double) a
{
real = a;
}
-(void) setImaginary: (double) b
{
imaginary = b;
}
-(void) setReal: (double) a andImaginary: (double) b
{
real = a;
imaginary = b;
}
-(double) getReal
{
return real;
}
-(double) getImaginary
{
return imaginary;
}
-(Complex *) add: (Complex *) InComp
{
Complex *OutComp = [[Complex alloc] init];
[OutComp setReal: real + [InComp getReal] andImaginary: imaginary + [InComp getImaginary] ];
return OutComp;
}
-(void) print
{
printf ("(%d + %di) ", real , imaginary ); // egal ob %di oder %d i (%d = single char)
}
@end
--------------------------- main.m
#import "Complex.h"
int main(int argc, char *argv[])
{
Complex *Comp = [[Complex alloc] init];
[Comp setReal: 0.1];
[Comp setImaginary: 2.0];
[Comp print];
[Comp free];
}
-------------------------- Ergebnis in der console:
(-1717986918 + 1069128089i)
ähm ja ....
bei
[Comp setReal: 0.0];
[Comp setImaginary: 0.0];
kommt
(0 + 0i)
(auch bei statt double -> float)
HILFE!!!!