Can a pointer of a derived class be type cast to the pointer of its base class?
c++
Solution
Yes. Conversion from a pointer to a derived class to a pointer to a base class is implicit. Thus, the following is perfectly fine:
struct B { };
struct D : B { };
D* my_d_ptr = new D;
B* my_d_ptr_as_a_b_ptr = my_d_ptr;
Problem
The pointer of derived class returned by new can be type cast to the pointer of its base class. Is this true or false? I know dynamic_cast can be used to cast downside. Generally, how to cast a pointer of derived class to a pointer of its base class?