Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why do you need that? Do you want to get rid of all of them?</p> <p>C-style casts for fundamental types like <code>(double)</code> are safe and looks much better than <code>static_cast&lt;double&gt;()</code>. I personally prefer this style.</p> <p>In case of polymorphic classes, the problem of C-style casts is grossly exaggerated imho. It may be a problem only if you use multiple inheritance and have to do cross casting. By default, C-style casts won't work there. But in most cases <code>()</code> works exactly like <code>static_cast&lt;&gt;()</code> and I wouldn't waste time on replacing them. Anyway, for polymorphic types I use C++-style casts when write new code or change something.</p> <p>UPDATE:</p> <p>Guys, it seems I expressed my opinion not so clearly. Yes, I know the theory: C++-cast is good, C-cast is evil. This rule (and most others) is needed to save newbies from C++. But it doesn't mean that you always need to follow it.</p> <p>My point is that C-style casts are not so terrible. If you write some function like</p> <pre><code>int convertFooToBar(double i_foo) </code></pre> <p>, there are no reasons to use C++-style casts in implementation. They are not safer than <code>(int)</code> but look messy. Casting is not tricky in such case. It is nothing bad or tricky in casting at all: sometimes casts are natural.</p> <p>About searching: I don't remember that I was searching for any cast statement in last 10 years, though I'm maintaining several million lines of legacy C++ code on daily basis. I don't even remember any serious problem due to wrong casting.</p> <p>Original question is about replacing already written C-style casts. So, my answer is:</p> <blockquote> <p>Yes, C++-style casts are better and safer than C-style ones. But it doesn't mean that you need to search for old ones in your code and try to get rid of all of them. Actually, it is not a real problem. Just don't waste your time. You may spend it on searching and deleting some out-of-date code. It would be more useful for your code base.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload