• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Confused about superclass initializers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Confused about superclass initializers


  • Subject: Confused about superclass initializers
  • From: Roland King <email@hidden>
  • Date: Fri, 27 Mar 2009 22:53:47 +0800

I've thought myself into a hole in a subclass here ....

If I have a class Foo with a subclass Bar, which adds say 2 new variables, in Bar's init method I do the usual

	self = [ super init ];

after someone called me with

	Bar *myBar = [ [ Bar alloc ] init ];

at the point I call that, 'self' is a Bar, it was alloc()ed to be long enough for a Bar. But it's quite possible that Foo's init will not init the object it's given, it will throw it away and return me a totally different Foo, [ super init ] doesn't have to return the same thing you sent it. But if that happens, it will be a Foo returned, it won't be a Bar, Foo's constructor has no idea that it's really meant to be making a Bar, it won't have enough memory allocated to be a Bar.

Then bad things will happen when I try to set the Bar variables as I don't have enough memory for it.

I must have missed something here. _______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Confused about superclass initializers
      • From: Alexander Spohr <email@hidden>
    • Re: Confused about superclass initializers
      • From: Michael Ash <email@hidden>
  • Prev by Date: Re: Getting the Generic Hard Disk Icon?
  • Next by Date: Re: Confused about superclass initializers
  • Previous by thread: Re: Preventing highlight of RowSelection in NSTableView
  • Next by thread: Re: Confused about superclass initializers
  • Index(es):
    • Date
    • Thread