Specify cmath's pow function and not locally declared one
-
11-02-2021 - |
Question
When calling ans+= c[i] * pow(x,i);
, xCode is complaining "Too many arguements to function call, expected 1 have 2". I have a locally defined function as follows:
Polynomial pow(unsigned int n) const;
and a constructor:
Polynomial(const double t = 0.0);
How can I specify that I would like to use cmath's pow function and not the locally defined one?
Thanks for the help!
Solution
Well, assuming you're keeping all your own stuff out of the std
namespace (and, if you're not, you should be, since that was the entire raison d'être of namespaces), you can just use std::pow()
.
See the following code for an example:
#include <iostream>
#include <cmath>
int pow(int x, int y) { return -1; }
int main() {
std::cout << std::pow(3,2) << std::endl;
return 0;
}
OTHER TIPS
I'm going to assume that by "locally defined" you mean a member of a class, since ordinarily function overloading would be able to tell the difference between the two functions; a class member will hide a similarly named function at global scope.
Just use ::pow
if you can't change the name of the locally defined function.