Reputation: 26333
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?
Upvotes: 6
Views: 26647
Reputation: 132994
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
Upvotes: 2
Reputation: 23428
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.
Upvotes: 10
Reputation: 726569
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.
Upvotes: 1