dynamic_cast failing weirdly
dynamic_cast failing weirdly
- Subject: dynamic_cast failing weirdly
- From: "Tim Conkling" <email@hidden>
- Date: Tue, 24 Jul 2007 19:34:21 -0400
I have a bizarre situation in a project that I'm porting from Windows (I just finally got everything to compile and link, so I'm really just starting to play with the project, and with Xcode). I have RTTI enabled for the project (and each of the several libraries that it links against) via the "Enable C++ Runtime Types" build setting, and dynamic_casts are resolving to NULL when they really shouldn't be. The situation looks roughly like this:
In MyLib:
class A { //... };
(a function):
static A* GetA() { // return some A* }
In MyApp:
class B : public A { //... };
(some code):
A* a = GetA();
B* b = dynamic_cast<B*>(a);
ASSERT(NULL != b);
// do something with b
That assert is failing - b is NULL, and it shouldn't be. My 'a' really is a 'b', and it's non-NULL -- I can verify this in the debugger, and a simple static cast from a to b works fine (and also, this code works as expected with Visual Studio, where it's being ported from).
(The reality of the situation is actually a little more complex: there are three classes, A, B, and C. B is a subclass of A, and C is a subclass of B. A is defined in a library, B is defined in a library that depends on the first library, and C is defined in my app. The dynamic_cast that's failing, in this particular instance, is taking place inside B's library, on an instance of C -- so I have an A*, that's really a C*, and I'm dynamic_casting it to a B* inside B's library, and that's what's failing. All of these binaries -- the two static libraries, and the application -- are separate Xcode projects that, as much as possible, share configuration data through .xcconfig files).
It seems like I've probably misconfigured something somewhere, but I'll be damned if I can figure out what. FWIW (and I only mention this because I've seen it come up a few times in the short time I've been lurking the list), I'm not using ZeroLink.
Thanks,
Tim
_______________________________________________
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