sqrt() pow() fabs() 不起作用
我正在尝试编译我的程序,其中我使用 sqrt pow 和 fabs 等函数。我确实包含了 math.h,但由于某种原因,我收到如下错误:
error C2668: 'fabs' : ambiguous call to overloaded function
其余函数相同 我已经包含了:
#include "stdafx.h"
#include "math.h"
我尝试包含但仍然存在相同的错误。 有谁知道为什么他们不被认可吗? 我的文件是.cpp而不是.c,但它是一个MFC项目。
谢谢
i am trying to compile my program where i am using the functions like sqrt pow and fabs. I do have math.h included but for some reason i get errors like:
error C2668: 'fabs' : ambiguous call to overloaded function
same for the rest of the functions
i have this included:
#include "stdafx.h"
#include "math.h"
i tried including but still same errors.
Does anyone know why they are not being recognized?
my file is .cpp not .c but it is an MFC project.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为这些函数针对多种类型进行了重载:float、double 和 long double。因此,如果您传入一个整数,编译器不会选择哪一个。一个简单的解决方法是简单地传递一个双精度值(或将您传递的值乘以 1.0),这应该可以解决问题。
否则:
It's because those functions are overloaded for several types: float, double and long double. Thus, if you pass in an integer, the compiler doesn't which one to choose. An easy fix is to simply pass a double (or multiply what you pass in by 1.0), this should fix the problem.
otherwise: