• 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: Crash in virtual method call
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crash in virtual method call


  • Subject: Re: Crash in virtual method call
  • From: Steve Checkoway <email@hidden>
  • Date: Thu, 12 Jun 2008 13:47:39 -0700


On Jun 12, 2008, at 9:30 AM, Brian Stern wrote:

Is your inheritance hierarchy deeper than just the Base classes and a single Derived layer? Sometimes in cases like this you need a double typecast. Something like:

Base1* b = (Base1*) (Derived1*) aDerived2;


No. If your hierarchy looks like:

 Base1      Base2
   |          |
Derived1   Derived2
       \   /
        Foo

and you have

Derived2 *d2 = new Foo;

and you want to cast d2 to Base1, it would be:

Base1 *b1 = dynamic_cast<Base1 *>(d2);

You shouldn't ever be doing c-style casts on objects with multiple inheritance and I honestly can't think of a reason to use 2 casts. C- style casts of pointers don't change the value of the pointer.

--
Steve Checkoway

    "Anyone who says that the solution is to educate the users
    hasn't ever met an actual user." -- Bruce Schneier




Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Crash in virtual method call (From: Doug Hill <email@hidden>)
 >Re: Crash in virtual method call (From: Jens Alfke <email@hidden>)
 >Re: Crash in virtual method call (From: Doug Hill <email@hidden>)
 >Re: Crash in virtual method call (From: Brian Stern <email@hidden>)

  • Prev by Date: How do I create a nib? ...
  • Next by Date: Re: Crash in virtual method call
  • Previous by thread: Re: Crash in virtual method call
  • Next by thread: Re: Crash in virtual method call
  • Index(es):
    • Date
    • Thread