From: Steffen (sb123++at++gmx.de)
Date: 02/04/2003 02:02:09
Since pfNode is polymorph
virtual ~pfNode();
and pfDCS inherits from it via pfSCS and pfGroup,
I do not understand the following crash using dynamic_cast for safety:
(pfNode* ch; inserted to find the crash)
pfNode* gExt = pfdLoadFile("any.flt");
if (gExt) {
//make instance
pfGroup* inst = new pfGroup;
pfDCS* d = new pfDCS;
inst->addChild(d);
d->addChild(gExt);
//clone 'inst' and move
unsigned int n = 100;
std::vector<pfGroup*> g(n, (pfGroup*)(0));
for (unsigned int i=0; i<n; i++) {
g[i] = (pfGroup*)inst->clone(0);
pfNode* ch = g[i]->getChild(0);
pfDCS* d = (pfDCS*)(ch); //works
// d = dynamic_cast<pfDCS*>(ch); //crashes!
if (d) d->setTrans(4, 3*i, 0);
m_pGTerrain->addChild(g[i]);
}
}
Any hint?
I'm using MSVC++ 6 and RTTI is on - works with other classes.
Steffen
This archive was generated by hypermail 2b29 : Tue Feb 04 2003 - 02:04:16 PST