Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"more than one instance of overloaded function "std::pow" matches the argument list"

With C++, I try to

#define TINY std::pow(10,-10)

I give the code with the #include and namespace information for the class (.h) where TINY is defined

#pragma once
#include "MMath.h"
#include <string>
#include <cmath>
#include <vector>

using namespace std;

#define TINY std::pow(10,-10)

I use TINY in some function implementation in .cpp file, and TINY gives error

IntelliSense: more than one instance of overloaded function "std::pow" matches the argument list

What is right syntax?

like image 615
kiriloff Avatar asked Mar 04 '12 12:03

kiriloff


3 Answers

Edit: I do agree with the commenters saying that using std::pow() in place of a literal constant is unnecessary - so for this particular problem, go with the 1.0E-10 constant; my explanation of the actual error you were getting and the way to solve it still stands.

This has nothing to do with your #define. std::pow() is an overloaded function, and none of its overloads take (int, int) as arguments. You should provide arguments with types which unambiguously select an overload. Depending on the type of return value you want, you'll probably want to select one of these overloads:

      float pow (       float base,       float exponent );
     double pow (      double base,         int exponent );
long double pow ( long double base,         int exponent );

which you can invoke as follows:

std::pow(10.0f, -10.0f)
std::pow(10.0, -10)
std::pow(10.0L, -10)

respectively.

like image 127
pmdj Avatar answered Nov 03 '22 00:11

pmdj


I think the best way is to define a constant variable and initialize it without using the pow function, like this

const double TINY = 1E-10; //1e-10 is 10 to the power of -10
like image 36
Armen Tsirunyan Avatar answered Nov 02 '22 23:11

Armen Tsirunyan


Try using std::pow(10.0,-10.0) instead: std::pow has multiple overloads matching your argument list; specifying 10.0,-10.0 forces the use of the specific overload:

double pow(double base, double exponent);

Note that this #define may be suboptimal depending on the use of TINY: every time you use it in your code, a call will be made to std::pow to calculate the same value. A better approach would be to use a static variable, set it once, and use it from that point on.

like image 22
Sergey Kalinichenko Avatar answered Nov 02 '22 23:11

Sergey Kalinichenko