• 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
Re: Initialize a subclass object with a base class object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Initialize a subclass object with a base class object


  • Subject: Re: Initialize a subclass object with a base class object
  • From: "Liviu Andron" <email@hidden>
  • Date: Tue, 20 May 2008 09:50:08 +0300

On Tue, May 20, 2008 at 2:35 AM, <email@hidden> (!sic)
wrote:
>
>
> > I am not sure I understand the OP's question, but the shortest answer
> seems to be to override the super class's designated initializer.
>
> I think he wants an Objective-C equivalent to a C++ copy constructor. That
> is...
>
> ButtonCell *bCell = getFromSomewhere();
> MyButtonCell *mCell = new MyButtonCell( &bCell );
>
> ... and have mCell be a copy of bCell, but with a new class type. I
> don't think that Obj-C generally supports this in any of its patterns.
>
> What I suspect he REALLY wants to do is go into IB and set a custom
> class for his button cell. But that's just a guess.


I guess he can REALLY go into IB and change the custom class, but what if he
REALLY wants to create more objects from the ones in IB (the ones in IB
being prototypes: NO, it's not a one-to-one relationship) ? How does the
poor OP (sic!) copy those into the real ones ? Besides, the prototypes don't
have to be MyButtonCell objects and if somebody change the interface in IB
he doesn't have to wonder what is MyButtonCell.

setRepresentedObject: is a hint, thanks, but it doesn't resolve the problem
either: he MUST copy every property from the original NSButtonCell (font,
attributedTitle, imageDimsWhenDisabled, etc). He could use copyWithZone (or,
better, memcpy) , but maybe there's a pointer there, that will be used after
some copy is destroyed :((

PS
"
When you ask a question, whenever possible please:
1. Describe what your high-level goal is
"

My high-level goal:
   "he wants an Objective-C equivalent to a C++ copy constructor"

"How I Learned to Stop Worrying and Love Cocoa"
_______________________________________________

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: Initialize a subclass object with a base class object
      • From: Andreas Mayer <email@hidden>
    • Re: Initialize a subclass object with a base class object
      • From: "stephen joseph butler" <email@hidden>
  • Prev by Date: Re: cocoa mentoring - Berlin, Germany
  • Next by Date: Problem with updating NSProgressIndicator
  • Previous by thread: Re: Initialize a subclass object with a base class object
  • Next by thread: Re: Initialize a subclass object with a base class object
  • Index(es):
    • Date
    • Thread