si prega di dare uno sguardo sul seguente codice: ------- .hNSCopying & Inheritance
@interface BankAccount : NSObject<NSCopying>
{
double accountBalance;
long accountNumber;
NSString *CustomerName;
NSString *AccountType;
}
-(void) setAccount: (long) y andBalance: (double) x;
-(void) setCustomerName: (NSString*) name andAccountType: (NSString*) type;
-(id)copyWithZone:(NSZone *)zone;
@end
@interface Savings : BankAccount
{
int number;
NSString *Offer;
}
-(void) setSavingNumber: (uint8_t) num andOffer: (NSString*) offer;
-(id)copyWithZone:(NSZone *)zone;
@end
---------- .m
@implementation BankAccount
-(void) setAccount: (long) y andBalance: (double) x
{
accountNumber = y;
accountBalance = x;
}
-(void) setCustomerName: (NSString*) name andAccountType: (NSString*) type
{
CustomerName = name;
AccountType = type;
}
-(id)copyWithZone:(NSZone *)zone
{
BankAccount *accountCopy = [[BankAccount allocWithZone: zone] init];
[accountCopy setAccount: accountNumber andBalance: accountBalance];
[accountCopy setCustomerName:CustomerName andAccountType:AccountType];
return accountCopy;
}
@end
@implementation Savings
-(void) setSavingNumber: (uint8_t) num andOffer: (NSString*) offer
{
number = num;
Offer = offer;
}
-(id)copyWithZone:(NSZone *)zone
{
Savings * clone = [super copyWithZone:zone];
[clone setSavingNumber:number andOffer:Offer];************** error *********
return clone;
}
@end
Quando eseguire questo codice ::::::
Savings* account1;
Savings* account2;
account1 = [[Savings alloc] init];
[account1 setAccount:10 andBalance:1000.10];
[account1 setCustomerName:[NSString stringWithFormat:@"%@",@"Deepak"] andAccountType:[NSString stringWithFormat:@"%@",@"Savings"]];
[account1 setSavingNumber:2001 andOffer:@"Bad"];
account2 = [account1 copy];
#
io non so cosa è sbagliato con il codice per favore mi aiuti. Grazie in anticipo.
Grazie Deepak
Si prega di formattare il codice e fare una domanda. Qual è il comportamento attuale, quale sarebbe il previsto. –