Re: Crash in virtual method call
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