Hello guys,
I found this solution to exercise 13.4:
Fraction *add(Fraction *array[], int lenght)
{
Fraction *result = [[Fraction alloc] init];
[result setTo:0 over:1];
Fraction *temp;
for(int i=0; i<15;++i)
{
temp = [result add: array[i]];
[result release];
result = temp;
}
return result;
}
It works but...

... I would like someone please explain to me:
1) why you need to use a variable "temp" instead of incrementing directly "result" ;
2) why "temp" is of the same (Fraction *) type as "result" but you do not have to write the [[Fraction alloc] init] part for it as you do fot the "result". I have a VB/C# background, just started with Objective-c.
NOTE: I am using XCode 4.3 and I have
NOT ENABLED ARC because I want to get used to manage the memeory by myself.
In fact the **not right working** code I wrote before I browsed for the solution was:
Fraction *add(Fraction *array[], int lenght)
{
Fraction *result = [[Fraction alloc] init];
[result setTo:0 over:1];
for(int i=0; i<15;++i)
{
result = [result add: array[i]];
}
return result;
}
This would have worked in C#, without the need of the "temp".
Thanks
Nicola