re-interpret cast

S

Stuart Redmann

Hi all,
Why re-interpret cast should not be used in practise?

Where does it say so?

There are many cases where reinterpret_cast is the only chance to get what you
want. Your statement should better be re-phrased to:
If you have to use casts, try to use dynamic_cast, static_cast or const_cast;
reinterpret_cast should be your last resort.

Regards,
Stuart
 
J

Jim Langston

Stuart said:
Where does it say so?

There are many cases where reinterpret_cast is the only chance to get
what you want. Your statement should better be re-phrased to:
If you have to use casts, try to use dynamic_cast, static_cast or
const_cast; reinterpret_cast should be your last resort.

reinterpret cast should be used as little as possible according to bjorn,
other ways to accomplish the same thing should be tried first. However,
that being said, there are times when reinterpret cast is the only way to do
something.

Why shouldn't reinterpret cast be used if it can be helped? It breaks type
safety. It is dangerous. It can work differently on different machines.
It can make code hard to read.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top