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!

有帮助吗?

解决方案

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;
}

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top