I was working on a program this morning that required me to use the pow function (to compute 2^i at one point, and 3^i at another). I used the following code:
[CODE=cpp]std::vector<int > increments(stat ic_cast<int>(lo g(a.size() + 1)/log(2)));
for (int i = 0; i < increments.size (); i++)
increments[i] = pow(2, i);[/CODE]
and got an error message saying "The call to pow(int, int&) is ambiguous. Candidates are:" and proceeded to list all sorts of pow functions using doubles, long doubles, floats, etc., but no int or long int versions!
Eventually I had to change that last line to
[code=cpp]increments[i] = static_cast<int >(pow(static_ca st<double>(2), i));[/code]
in order to get the dang thing to compile. It produced expected results, but still frustrated me.
Why is there no pow(int, int) function available in the cmath header file?
[CODE=cpp]std::vector<int > increments(stat ic_cast<int>(lo g(a.size() + 1)/log(2)));
for (int i = 0; i < increments.size (); i++)
increments[i] = pow(2, i);[/CODE]
and got an error message saying "The call to pow(int, int&) is ambiguous. Candidates are:" and proceeded to list all sorts of pow functions using doubles, long doubles, floats, etc., but no int or long int versions!
Eventually I had to change that last line to
[code=cpp]increments[i] = static_cast<int >(pow(static_ca st<double>(2), i));[/code]
in order to get the dang thing to compile. It produced expected results, but still frustrated me.
Why is there no pow(int, int) function available in the cmath header file?
Comment