Is there any CInt function - VB in c++?
-
Stephen Hewitt wrote:
any C-style casts; they should never be used in C++ code.
Personally I guess that the 1-voter doesn't feel comfortable with the sentence above.
Maxwell Chen
I would guess so - nevertheless they shouldn't be used. Here are some reasons: - A wrong "bad" can cause havoc yet, if C-style casts are used you can’t “grep” the source code for them. - There are many distinct reasons to cast. For example, one is to remove const-ness; another is to “down-cast” in a class hierarchy. With C-style casts all casts look the same and so you have to guess at the intent. Function style casts are explicit and self documenting in this respect. - With C-style casts a simple mistake can change the type of cast and result in unintentional behaviour. For example if your casting to remove const-ness and then you change the type you’re casting it can changes into a “reinterpret” cast. With function style casts the compiler makes sure you can’t cast “more” then you should. i.e. a
const_cast
can only remove const-ness and not change the type. - Casting is ugly – a well designed program shouldn’t have any – or at most only a few in the lowest level of a system. Casts should be ugly as design errors should be visible. I could go on. There are just so many problems it just not funny. Steve -
I would guess so - nevertheless they shouldn't be used. Here are some reasons: - A wrong "bad" can cause havoc yet, if C-style casts are used you can’t “grep” the source code for them. - There are many distinct reasons to cast. For example, one is to remove const-ness; another is to “down-cast” in a class hierarchy. With C-style casts all casts look the same and so you have to guess at the intent. Function style casts are explicit and self documenting in this respect. - With C-style casts a simple mistake can change the type of cast and result in unintentional behaviour. For example if your casting to remove const-ness and then you change the type you’re casting it can changes into a “reinterpret” cast. With function style casts the compiler makes sure you can’t cast “more” then you should. i.e. a
const_cast
can only remove const-ness and not change the type. - Casting is ugly – a well designed program shouldn’t have any – or at most only a few in the lowest level of a system. Casts should be ugly as design errors should be visible. I could go on. There are just so many problems it just not funny. SteveStephen Hewitt wrote:
I could go on. There are just so many problems it just not funny.
What did you mean by that?
Maxwell Chen
-
Stephen Hewitt wrote:
I could go on. There are just so many problems it just not funny.
What did you mean by that?
Maxwell Chen
Only that I could have made the list of problems with C-style casts longer. Steve