Search Results

Search found 1 results on 1 pages for 'gavinbeatty'.

Page 1/1 | 1 

  • Why does gcc warn about incompatible struct assignment with a `self = [super initDesignatedInit];' c

    - by gavinbeatty
    I have the following base/derived class setup in Objective-C: @interface ASCIICodeBase : NSObject { @protected char code_[4]; } - (Base *)initWithASCIICode:(const char *)code; @end @implementation ASCIICodeBase - (ASCIICodeBase *)initWithCode:(const char *)code len:(size_t)len { if (len == 0 || len > 3) { return nil; } if (self = [super init]) { memset(code_, 0, 4); strncpy(code_, code, 3); } return self; } @end @interface CountryCode : ASCIICodeBase - (CountryCode *)initWithCode:(const char *)code; @end @implementation CountryCode - (CountryCode *)initWithCode:(const char *)code { size_t len = strlen(code); if (len != 2) { return nil; } self = [super initWithCode:code len:len]; // here return self; } @end On the line marked "here", I get the following gcc warning: warning: incompatible Objective-C types assigning 'struct ASCIICodeBase *', expected 'struct CurrencyCode *' Is there something wrong with this code or should I have the ASCIICodeBase return id? Or maybe use a cast on the "here" line?

    Read the article

1