错误:模糊旧声明'double round(double)'

use*_*241 5 c++

/usr/include/i386-linux-gnu/bits/mathcalls.h:311:1: error: ambiguates old declaration ‘double round(double)’
g.cpp: In function ‘int round(double)’:
g.cpp:14:24: error: new declaration ‘int round(double)’
/usr/include/i386-linux-gnu/bits/mathcalls.h:311:1: error: ambiguates old declaration ‘double round(double)’
Run Code Online (Sandbox Code Playgroud)
#include <iostream>
#include <cmath>
using namespace std;

int round(double number);

int main()
{
    double number = 5.9;
    round(number);
    return 0;
}
int round(double number)
{
    return static_cast<int>(floor(number + 0.5));
}
Run Code Online (Sandbox Code Playgroud)

为什么我的编译器显示错误

Jos*_*eld 13

这里的错误很明显.该<cmath>头已经引入的功能double round(double),你不能超载基于返回类型.是的,它是在std命名空间中定义的,但是你正在做using namespace std;(它也是实现定义它是否在注入之前首先在全局命名空间中定义std).为了完全可移植,您需要为您的函数指定一个不同的名称或将其粘贴到另一个名称空间中 - 或者,当然,使用提供给您的round功能<cmath>.但也摆脱它using namespace std;.