iccaros Posted January 25, 2006 Report Share Posted January 25, 2006 ok I am still working on my statistics program,I have it working (I think)but I get a compiler warning.. I believe its because this is a C way of doing this..I have slot defined as a double for the math but need to retrun a int for the place in the array (as there is no place 0.456)here is how I converted double slot to an int.return slot = (int) slot;better option for c++?Thanks Quote Link to post Share on other sites
jcl Posted January 26, 2006 Report Share Posted January 26, 2006 (edited) The warning is probably because slot is a double and function is declared as returning an int. You're casting the value of slot [edit: another weird typo, I need to run some tests] to int and then assigning it back to a double which is then implicitly converted by the compiler to int. g++ generates warnings when it does implicit conversion. The warning doesn't necessarily mean there's anything wrong: fp to integral conversion is well-defined iff the integeral type can exactly represent the whole part of the fp value. You're (probably) going to get the same result with or without the cast so you can ignore the warning if you like.Anyway C-style casts are perfectly valid, soreturn (int)slot;will work. The idiomatic C++ would bereturn static_cast<int>(slot);but there are a lot of people who wouldn't bother with the C++-style cast in this case. Edited January 26, 2006 by jcl Quote Link to post Share on other sites
iccaros Posted January 26, 2006 Author Report Share Posted January 26, 2006 Thanks.. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.