How can I get away from casting in C++? -


In C ++ you can cast a few ways, c-style casting or C ++. A host of Bjarne Stroustrup and other C ++ experts say that there should be no casting in a good design.

Can you help redesign the code given below so that artists can get rid of it?

  zero CProgressBar :: SetPosition (int nPos); // Unable to change zero: CSaveDialog :: UpdatePosition (double dcrogress) {double percentage off progress = display * 100; M_p progress bar- & gt; Settlement (static_cast & lt; int & gt; (percentage off progress); }  

I can modify UpdatePosition, but not SetPosition

I think casting can be fine in arithmetic. The type of casting that should really be avoided is your own class hierarchy above and below (or across).

In addition to casting this into arithmetic, you probably want to be more careful before casting it to int before ceil or Floor should be applied. I'm not sure that it is entirely determined how the artist will be round (i.e. + on the side of the INF, in the direction, or toward zero)


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -