C++:使用 std::sin(x) 与 sin(x)

问题描述

对 cmath 方法使用 std 范围解析和不使用它有什么区别?

#include <cmath>
double a = std::atan(0);

对比

#include <cmath>
double a = atan(0);

我问的原因是因为我正在构建一个自定义的“atan”静态方法,当从静态方法中调用它时,它显然与静态方法本身的名称冲突。所以在这里我通过使用“std::”来避免冲突,但它确实让我思考了引擎盖下发生的事情。

头文件:

class MathCustom
{
public:
  static double atan(int x,int y);
};

cpp 文件:

#include <cmath>

double MathCustom::atan(int x,int y)
{
  if (x == 0 && y == 0) { return 0; } // undefined angle,but will be set to 0;
  if (x == 0) { // y != 0
    return (y > 0) ? std::atan(INFINITY) : std::atan(-INFINITY);
  } else { // x != 0 && y: any value
    return std::atan(static_cast<double>(y) / static_cast<double>(x));
  }
}

赞赏!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...