Here is the code :
@implementation Accumulateur
// Constructor
- (id) init
{
return ([self initWithTotal:0]);
}
- (id) initWithTotal:(int)aTotal
{
AccumulateurMoyen *ac;
if ((ac = [[AccumulateurMoyen alloc] init]) == nil)
{
[self release];
return (nil);
}
return ([self initWithTotal:aTotal andAccumulateurMoyen:ac]);
}
- (id) initWithTotal:(int)aTotal
andAccumulateurMoyen:(AccumulateurMoyen *)aAcMoyen
{
if (self = [super init])
{
[aAcMoyen retain];
[acMoyen release];
acMoyen = aAcMoyen;
total = aTotal;
}
return (self);
}
@end
The problem is here : if ((ac = [[AccumulateurMoyen alloc] init]) == nil)
As I redefined init, the init called is mine and not that of NSObject…
I dont have idea, how i can do that correctly (AccumulateurMoyen is subclass of Accumulateur)
Thx you
You have probably undesired recursion there:
[[AccumulateurMoyen alloc] init]tries to create newAccumulateurMoyenbut that results in nestedinitWithTotal:which again tries to create anotherAccumulateurMoyeninstance etc.I.e. your code tries to create
Accumulateurwhich has memberacMoyenset to new instance ofAccumulateurMoyen, which again has itsacMoyenset to another new instance ofAccumulateurMoyenetc.You must to break the endless recursion. E.g. in
initWithTotal:, replace the linewith
I.e. the nested
AccumulateurMoyenwill have its member set tonil.