J
Jakob Bieling
Hi,
I have a question about casting and using the casted pointer: Suppose I
have a 'base' class and a 'derived' class (which is derived from 'base').
Now I have this scenario:
base* p1 = new base ();
base* p2 = new derived ();
derived* d1 = (derived*) p1;
derived* d2 = (derived*) p2;
Does the cast itself already produce undefined behaviour? Or will I get
there when using 'd1'? I am asking because I have a similiar scenario, where
the casted pointer is used in an if-statement, like this:
if (p2->is_derived () && d2->func_only_present_in_derived_class ())
{
}
thanks
I have a question about casting and using the casted pointer: Suppose I
have a 'base' class and a 'derived' class (which is derived from 'base').
Now I have this scenario:
base* p1 = new base ();
base* p2 = new derived ();
derived* d1 = (derived*) p1;
derived* d2 = (derived*) p2;
Does the cast itself already produce undefined behaviour? Or will I get
there when using 'd1'? I am asking because I have a similiar scenario, where
the casted pointer is used in an if-statement, like this:
if (p2->is_derived () && d2->func_only_present_in_derived_class ())
{
}
thanks