• 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: C++: what could cause dynamic_cast<> to fail?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++: what could cause dynamic_cast<> to fail?


  • Subject: Re: C++: what could cause dynamic_cast<> to fail?
  • From: Kai BrĂ¼ning <email@hidden>
  • Date: Mon, 25 Jan 2010 09:02:17 +0100

On 24.1.2010, at 18:04, Jens Alfke wrote:

>
> On Jan 23, 2010, at 1:01 PM, Dan Caugherty wrote:
>
>> (For the record, the function call logic is in a shared library, not that this should matter.)
>
> It does matter, actually. Multiple binaries play havoc with RTTI unless you're careful. I ran into this a few years ago.
>
> The problem is that you can end up with more than one copy of the 'value' class, if the class implementation is compiled into each binary. Ordinarily this won't matter because the two copies of the class are identical in their code, object layout and name. But RTTI identifies classes by pointer identity of their vtables, so the two 'value' classes won't show up as being the same for purposes of dynamic_cast.
>
> {This is a situation I call a "Great Roe", after an old Woody Allen treatise on mythical beasts: "The Great Roe is a beast with the head of a lion, and the body of a lion, but not the same lion."}
>
> The solution is to make sure that the source file defining the 'value' class ('value.cpp' or whatever) is only compiled into the shared library. That ensures there's only one copy of the vtable. Then you also have to make sure the library exports the symbols for 'value's vtable and methods, otherwise the other binaries will fail to link.

This may be of help:

http://developer.apple.com/mac/library/technotes/tn2007/tn2185.html

Kai

 _______________________________________________
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

  • Follow-Ups:
    • Re: C++: what could cause dynamic_cast<> to fail?
      • From: Dan Caugherty <email@hidden>
References: 
 >C++: what could cause dynamic_cast<> to fail? (From: Dan Caugherty <email@hidden>)
 >Re: C++: what could cause dynamic_cast<> to fail? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: C++: what could cause dynamic_cast<> to fail?
  • Next by Date: Re: Including different debug and release frameworks in a .app
  • Previous by thread: Re: C++: what could cause dynamic_cast<> to fail?
  • Next by thread: Re: C++: what could cause dynamic_cast<> to fail?
  • Index(es):
    • Date
    • Thread