Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
5-2-7 reinterpret_cast between derived classes?
#1
Dear MISRA team,

the term "unrelated type" leads to the question whether casting from a base to derived class pointer type and vice versa using reinterpret_cast shall be covered by the rule or not. Remark: I am perfectly aware that dynamic_cast and static_cast , resp., would be the right way for these purposes, so my question is rather academic.

I refer to the term "related type" as Stroustrup uses it concerning types "in the same class hierarchy" which is surely the case here.

Code:
class B {};
class D : public B {};

void f()
{
    D* dptr = new D();
    B* bptr = reinterpret_cast( dptr );
    D* dptr2 = reinterpret_cast( bptr ); // correct (yet ugly) when one knows where the base class pointer points to
}
<t></t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)