0

Possible Duplicate:
When should static_cast, dynamic_cast and reinterpret_cast be used?

class b
{
}
class d :public b
{
}

int main
{
 d* d_p = new d();
 b* b_p = static_cast<base*>(d_p);

 b* b_p = reinterpret_cast<base*>(d_p); // any difference will it make
 return 0;
}

So in the above example does static and reinterpret cast make any difference functionaly etc..? for me both are same in this scenario.

Community
  • 1
  • 1
G Mann
  • 441
  • 1
  • 4
  • 12
  • 2
    There is no difference in the sense that your program wouldn't compile regardless of which cast you prefer in this erroneous code :P – Nawaz Jun 14 '11 at 05:06
  • I have edited the code if you think it gives error due to return type. i just wrote the code here directly just to explain. – G Mann Jun 14 '11 at 05:37

1 Answers1

0

Yes, there will be a difference. You should check here

Sanchit Paurush
  • 6,114
  • 17
  • 68
  • 107
  • I went through the link and found the below explaination for same example which i mentioned- Derived d; BaseB* bp = static_cast(&d); // valid: bp now points to BaseB subobject of d BaseB* rp = reinterpret_cast(&d); // probably not valid, could result in rp pointing at // the BaseA memory in d but with the BaseB* type. But here i am not fully convinced. can you please explain... – G Mann Jun 14 '11 at 05:52
  • I know the basic difference between these two. But my question is that in the my example does it make any any difference? – G Mann Jun 14 '11 at 08:01