由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - c++ std::abs(int) ambiguous?
相关主题
What is wrong with the code?请教c++的string vector问题,谢谢! (转载)
腆着脸在问一道namespace defined in another file
C++命名空间和算子重载关于c++的constructor的面试题
一个关于C++ template和overload的问题一个关于assignment constructor和expection的问题
namespace 问题a simple question for C++ class
[合集] 问个面试题请问一个exception题目
[合集] 怎样有效的传递C静态数组的变量名?关于 VC++ vitual, reload 和 derive的一个问题...
请教一个c++ reference问题发个初级面试题
相关话题的讨论汇总
话题: abs话题: int话题: double话题: include话题: std
进入Programming版参与讨论
1 (共1页)
z****e
发帖数: 2024
1
#include
#include
#include
using namespace std;
后面用了abs()
error: call of overloaded ‘abs(double)’ is ambiguous
/usr/include/stdlib.h:691: note: candidates are: int abs(int)
没办法,把using namespace std;去掉,然后一个一个的using。编译通过了。
我估计是用了stdlib里边的abs,但是精度太差了。
怎么调用一个take double 的abs() 呢?
N***m
发帖数: 4460
2
fabs()?

【在 z****e 的大作中提到】
: #include
: #include
: #include
: using namespace std;
: 后面用了abs()
: error: call of overloaded ‘abs(double)’ is ambiguous
: /usr/include/stdlib.h:691: note: candidates are: int abs(int)
: 没办法,把using namespace std;去掉,然后一个一个的using。编译通过了。
: 我估计是用了stdlib里边的abs,但是精度太差了。
: 怎么调用一个take double 的abs() 呢?

z****e
发帖数: 2024
3
Thanks!!!
久违的记忆深处,这个函数终于开始闪闪发光。

【在 N***m 的大作中提到】
: fabs()?
t****t
发帖数: 6806
4
abs(int) is declared in stdlib.h (); while fabs(double) and
additional overloaded abs(double) is declared in math.h ().
if you want abs(int), but include only without , then
compiler won't know how to convert int to double/float/long double.
on the other hand, if you want abs(double) but you include only
without , compiler won't know how to convert double to int/long/long
long.
so make sure you included what you need.

【在 z****e 的大作中提到】
: #include
: #include
: #include
: using namespace std;
: 后面用了abs()
: error: call of overloaded ‘abs(double)’ is ambiguous
: /usr/include/stdlib.h:691: note: candidates are: int abs(int)
: 没办法,把using namespace std;去掉,然后一个一个的using。编译通过了。
: 我估计是用了stdlib里边的abs,但是精度太差了。
: 怎么调用一个take double 的abs() 呢?

t******s
发帖数: 119
5
zan!

long

【在 t****t 的大作中提到】
: abs(int) is declared in stdlib.h (); while fabs(double) and
: additional overloaded abs(double) is declared in math.h ().
: if you want abs(int), but include only without , then
: compiler won't know how to convert int to double/float/long double.
: on the other hand, if you want abs(double) but you include only
: without , compiler won't know how to convert double to int/long/long
: long.
: so make sure you included what you need.

z****e
发帖数: 2024
6
mater shifu: xin ku le.

long

【在 t****t 的大作中提到】
: abs(int) is declared in stdlib.h (); while fabs(double) and
: additional overloaded abs(double) is declared in math.h ().
: if you want abs(int), but include only without , then
: compiler won't know how to convert int to double/float/long double.
: on the other hand, if you want abs(double) but you include only
: without , compiler won't know how to convert double to int/long/long
: long.
: so make sure you included what you need.

1 (共1页)
进入Programming版参与讨论
相关主题
发个初级面试题namespace 问题
最初级的白痴C++问题[合集] 问个面试题
两个继承问题[合集] 怎样有效的传递C静态数组的变量名?
为什么我看不懂下面的code,是不是水平还不够?请教一个c++ reference问题
What is wrong with the code?请教c++的string vector问题,谢谢! (转载)
腆着脸在问一道namespace defined in another file
C++命名空间和算子重载关于c++的constructor的面试题
一个关于C++ template和overload的问题一个关于assignment constructor和expection的问题
相关话题的讨论汇总
话题: abs话题: int话题: double话题: include话题: std