Victor A. Wagner Jr. wrote: > Keanu Reaves wrote: >> hi shweta i'm frm india...The Question You Asked Has No Difference > you mean the results of the program will be the same. >> you can use one of them..but the thing is that it may give you >> unconditional results.if u r on orkut then gimme id.ok.! >> >> Thomas Hruska <[EMAIL PROTECTED]> wrote: Mickey Mathieson wrote: >> >>> --- shvetakapoor2002_cplusplus >>> <[EMAIL PROTECTED]> wrote: >>> >>> >>>> Hi All, >>>> >>>> Please help me in understanding what's the >>>> difference between the two >>>> statements below >>>> >>>> [1] cout << "Number: " << static_cast<int>(3.14159) >>>> << "\n"; >>>> >>>> [2] cout << "Number: " << (int)3.14159 << "\n"; >>>> >>>> Basically I want to know the difference in using >>>> static_cast<int> and >>>> using (int) >>>> >>>> Thanks, >>>> Shveta >>>> >>>> >>>> >>> http://www.cprogramming.com/reference/typecasting/staticcast.html >>> >>> >>> Mickey M. >>> Construction Partner Inc. >>> http://www.constructionpartner.com >>> >> Um... >> >> double result = static_cast<double>(4)/5; >> >> Pretty sure that won't work > of course it will
Okay. Conceded. Personally, I prefer making sure the compiler knows exactly what I mean and I never rely on implicit rules. It is a habit I've learned over the years after getting bitten by numerous bugs. So I will always prefer: double result = ((double)4) / ((double)5); OR double result = 4.0 / 5.0; >> Frankly, I've not seen much of a difference between the two types of >> casts and personally prefer the old C-style casts because it requires >> pressing fewer keys. > bad idea. Read Meyers on the topic I've read enough on static_cast to know it doesn't do much of anything different from C-style casting for fundamental data types (int, double, char, float, short, long, unsigned, signed). I use static_cast for classes and other more complex types though because there ARE compile-time benefits there. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.0 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
