N
Nick Keighley
Hi,
Is this code fundamentally broken?
class B
{
}
class D: public B
{
}
void proc(B* b)
{
D* d = dynamic_cast<D*>b;
// do things to d
}
void f()
{
B* b = new B;
proc (b);
delete b;
}
I know it isn't exception safe and should be using RAII (legacy code
:-( ).
I'm more worried about which destructor gets called. I assume ~D()
*doesn't* get called. I assume I should be deleteing D (or better using
RAII)
rather than B.
Unfortunatly B is heavily derived from and changing it will have to be
in a
lot of places. But then not fixing it...
Is this code fundamentally broken?
class B
{
}
class D: public B
{
}
void proc(B* b)
{
D* d = dynamic_cast<D*>b;
// do things to d
}
void f()
{
B* b = new B;
proc (b);
delete b;
}
I know it isn't exception safe and should be using RAII (legacy code
:-( ).
I'm more worried about which destructor gets called. I assume ~D()
*doesn't* get called. I assume I should be deleteing D (or better using
RAII)
rather than B.
Unfortunatly B is heavily derived from and changing it will have to be
in a
lot of places. But then not fixing it...