C++ Casting between template invocations -
suppose x<t> template class taking class parameter , a , b classes b being derived a without involvement of multiple or virtual inheritance (i.e. no pointer adjustments necessary when casting between a , b).
is safe perform chainsaw reinterpret cast x<a*> x<b*> or vice versa? of course, x<a*> no x<b*>, shouldn't these classes share same behaviour? because pointers used, memory layout should equal. thus, might okay let methods of x<b*> operate on instance x<a*>.
of course, somehow ruins type safety example insert element of a* x<b*>, out of scope of question.
it's better write this, if need it.
x<a*> a(new b()); x<b*> b( dynamic_cast<b*> ( a.get_pointer() ) ); if(b.get_pointer() != null) { ... }
Comments
Post a Comment