xcode dynamic_cast error with GCC4
xcode dynamic_cast error with GCC4
- Subject: xcode dynamic_cast error with GCC4
- From: Jim Crafton <email@hidden>
- Date: Fri, 2 Dec 2005 20:47:19 -0500
I have created a simple project that seems to demonstrate the problems
I've been having with xcode 2.2 and GCC4.
I have made a simple Carbon framework. Then added the following
classes to a header:
#include <string>
#include <typeinfo>
typedef std::string String;
class Base {
public:
virtual ~Base(){}
int m;
String name;
};
class Derived : public Base {
public:
Derived();
virtual ~Derived(){}
double d;
};
template <typename T>
class DoIt {
public:
void invoke ( Base* b ) {
T* t = dynamic_cast<T*>( b );
printf("Base: %p, converted to %s @ %p\n", b, typeid(T).name(), t );
}
};
and implemented the Derived() in a cpp file.
I set the target's setting such that it builds in $(HOME)/Library/Frameworks
I add a new executable target (C++ Tool) and add the following code to
the main.cpp
#include <iostream>
#include "TestCPP.h" // this is the header for the classes above
int main (int argc, char * const argv[]) {
Base* b = new Derived();
DoIt<Derived> d;
d.invoke( b );
Derived* dPtr = dynamic_cast<Derived*>(b);
printf( "dPtr = %p\n", dPtr );
delete b;
return 0;
}
I set the exe target to have it's framework search path to look in
$(HOME)/Library/Frameworks. From the Products folder, I drag the
CppLib (the name of the framework) over to the exe's "Link Binary With
Libraries" section. The build succeeds just fine.
I run the code and get the following output (the exe is named
"TestCPP", the framework is "CppLib":
[Session started at 2005-12-02 20:37:42 -0500.]
In Derived::Derived() 0x3020e0
Base: 0x3020e0, converted to 7Derived @ 0x0
dPtr = 0x0
TestCPP has exited with status 0.
Note that the results of the dynamic_cast are NULL! Why would this
occur? If I take the same code in the header of the framework lib and
simple put it directly in the main.cpp file, and comment out the
include, then when I run it, the dynamic_cast call works as expected.
Is this some known GCC bug? Is there a better place to report this? Is
there some workaround, or something completely obvious that I've
missed?
Thanks!
Jim
_______________________________________________
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