S
Sashi
class parent{
Parent(){};
~Parent(){};
}
Child: public Parent{
Child(){};
~Child(){};
}
void destroy( Parent *ptr)
{delete ptr;}
int main(int argc, char** argv){
Child c_ptr = new Child;
Parent p_ptr = new Parent;
destroy( c_ptr);
destroy(p_ptr);
exit 0;
}
I think this question must have been discussed to death but here it
goes again.
What'll happen above? Nothing catastrophic, as there is no dynamically
allocated memory. Am I right?
Also, what is the more general problem of doing such a delete? i.e.
deleting a child object pointed to by a parent pointer?
Thanks,
Sashi
Parent(){};
~Parent(){};
}
Child: public Parent{
Child(){};
~Child(){};
}
void destroy( Parent *ptr)
{delete ptr;}
int main(int argc, char** argv){
Child c_ptr = new Child;
Parent p_ptr = new Parent;
destroy( c_ptr);
destroy(p_ptr);
exit 0;
}
I think this question must have been discussed to death but here it
goes again.
What'll happen above? Nothing catastrophic, as there is no dynamically
allocated memory. Am I right?
Also, what is the more general problem of doing such a delete? i.e.
deleting a child object pointed to by a parent pointer?
Thanks,
Sashi