[SOLVED] You are not allowed to edit this page.
-
Hi,
Why I am not able to edit "this page":http://developer.qt.nokia.com/wiki/Integer_Division_gives_0 ?
I would like to replace the C style cast:
@double c = (double) a / b;@
with static_cast due to its advantages:
@double c = static_cast<double>(a/b);@
Using C style cast in C++ source code is a bad practice and should not exist in this code snippet!
Thanks,
Leon -
I don't know why the page is locked (someone else is trying to edit?)
But your correction is wrong!
You calculate the division using integers and cast that result to a double, which leads to the undesired reusult of 0. If you really want to use a c++ cast, then it must be
@
double c = static_cast<double>(a)/b;
@Using C-style casts for number conversions is acceptable, IMHO. So if you really want to add static cast, add it as an alternative.
-
[quote author="Volker" date="1304548096"]
But your correction is wrong!You calculate the division using integers and cast that result to a double, which leads to the undesired reusult of 0. If you really want to use a c++ cast, then it must be
@
double c = static_cast<double>(a)/b;
@
[/quote]Hi Volker,
Yes, of course! Thanks for pointing it out - it was a silly typing mistake I did not want to change the algorithm just the C style cast :)
I insist on adding an example with static_cast, but I still cannot edit the page. I will try again tomorrow. Btw do you get the same message if you try to edit it?
Thanks,
Leon -
If you want to add a few examples, you should include "this":http://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-and-reinterpret-cast-be-used too. It's a must read for everyone.
-
[quote author="Volker" date="1304549611"]Hi Leon,
yes, I get the same message, I cannot edit it either. If it's still locked tomorrow, I'll point some of the DevNet devs to it.[/quote]Hi Volker,
I still get the same message. Can you please notify DevNet devs about this issue?
[quote author="HuXiKa" date="1304549724"]If you want to add a few examples, you should include "this":http://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-and-reinterpret-cast-be-used too. It's a must read for everyone.[/quote]
Thanks for the link. You can add such kind of information to Qt DevNet wiki yourself too. Just find and appropriate article or create a new one. Do not hesitate and help us extend the wiki :)
10x,
Leon -
[quote author="Alexandra" date="1304610030"]It was locked. No idea why. Now it's unlocked and you can edit it. :)[/quote]
Alexandra, Volker, thanks! :) I have successfully add an example with static_cast.
Thanks,
Leon