a problem with dynamicCast

in Help Center
when i using the IceInternal::Handle seens a problem:
there is a shared lib:
// testlib.h
namespace XPP
{
class TestIceBase1 : public Ice::Object
{
int data_;
};
class TestIceBase2
{
int data_;
};
class TestIceObject1 : //virtual public TestBase ,
virtual public Ice::Object
{
};
typedef IceInternal::Handle<TestIceObject1> TestIceObject1Ptr;
class TestIceObject2 : virtual public TestIceBase1
{
};
typedef IceInternal::Handle<TestIceObject2> TestIceObject2Ptr;
TestIceBase1 * g_ice_object1;
TestIceBase1 * g_ice_object2;
TestXPPBase1 * g_XPP_object1;
TestXPPBase1 * g_XPP_object2;
void init_object();
}
// testlib.cpp
#include "testlib.h"
using namespace XPP;
void XPP::init_object()
{
g_ice_object1 = new TestIceObject1;
g_ice_object2 = new TestIceObject2;
g_XPP_object1 = new TestXPPObject1;
g_XPP_object2 = new TestXPPObject2;
}
then there is a exe program:
// test.cpp
int main( char ** argv , int argc )
{
XPP::init_object();
// test ice object1
{
printf("g_ice_object1: ");
// XPP::TestIceObject1Ptr testobj = XPP::TestIceObject1Ptr::dynamicCast( XPP::g_ice_object1 );
XPP::TestIceObject1 * testobj = dynamic_cast<XPP::TestIceObject1 *>( XPP::g_ice_object1.get() );
if( testobj ) {
printf("ok\n");
} else {
printf("failed\n");
}
}
// test ice object1
{
printf("g_ice_object2: ");
XPP::TestIceObject2Ptr testobj = XPP::TestIceObject2Ptr::dynamicCast( XPP::g_ice_object2 );
if( testobj ) {
printf("ok\n");
} else {
printf("failed\n");
}
}
}
after run the test program, the result always failed, can someone can tell me what is the problem is?
there is a shared lib:
// testlib.h
namespace XPP
{
class TestIceBase1 : public Ice::Object
{
int data_;
};
class TestIceBase2
{
int data_;
};
class TestIceObject1 : //virtual public TestBase ,
virtual public Ice::Object
{
};
typedef IceInternal::Handle<TestIceObject1> TestIceObject1Ptr;
class TestIceObject2 : virtual public TestIceBase1
{
};
typedef IceInternal::Handle<TestIceObject2> TestIceObject2Ptr;
TestIceBase1 * g_ice_object1;
TestIceBase1 * g_ice_object2;
TestXPPBase1 * g_XPP_object1;
TestXPPBase1 * g_XPP_object2;
void init_object();
}
// testlib.cpp
#include "testlib.h"
using namespace XPP;
void XPP::init_object()
{
g_ice_object1 = new TestIceObject1;
g_ice_object2 = new TestIceObject2;
g_XPP_object1 = new TestXPPObject1;
g_XPP_object2 = new TestXPPObject2;
}
then there is a exe program:
// test.cpp
int main( char ** argv , int argc )
{
XPP::init_object();
// test ice object1
{
printf("g_ice_object1: ");
// XPP::TestIceObject1Ptr testobj = XPP::TestIceObject1Ptr::dynamicCast( XPP::g_ice_object1 );
XPP::TestIceObject1 * testobj = dynamic_cast<XPP::TestIceObject1 *>( XPP::g_ice_object1.get() );
if( testobj ) {
printf("ok\n");
} else {
printf("failed\n");
}
}
// test ice object1
{
printf("g_ice_object2: ");
XPP::TestIceObject2Ptr testobj = XPP::TestIceObject2Ptr::dynamicCast( XPP::g_ice_object2 );
if( testobj ) {
printf("ok\n");
} else {
printf("failed\n");
}
}
}
after run the test program, the result always failed, can someone can tell me what is the problem is?
0
Comments
i already change the code like this:
class TestIceBase1 : public Ice::Object
{
int data_;
};
class TestIceBase2
{
int data_;
};
class TestIceObject1 : //virtual public TestBase ,
virtual public Ice::Object
{
};
typedef IceUtil::Handle<TestIceObject1> TestIceObject1Ptr;
class TestIceObject2 : virtual public TestIceBase1
{
};
typedef IceUtil::Handle<TestIceObject2> TestIceObject2Ptr;
but there still cann't dynamicCast ,
just return 0
:mad:
g_ice_object1 is a pointer, not a handle, so you cannot call get.
To get prompt assistance I suggest that you post something that does not use IceInternal types, is self-contained and compilable and demonstrates your problem and then we can help fix it. It also helps to know the version of Ice you are using, your compiler and finally your platform.
i think there is must my mistake, not the ICE.
The following combination of factors requires special attention:
1. under Linux
2. using shared libraries which are dynamicaly loaded (with dlopen)
3. performing dynamic casting: any dynamic casting is affected, basic std::dynamic_cast and Ice's ObjectPrx::dynamicCast().
Read about it here:
GCC Frequently Asked Questions - GNU Project - Free Software Foundation (FSF)
a somewhat related post is here:
http://www.zeroc.com/forums/bug-reports/1319-dlopen-linux.html#post5556