C++ 如何解决终端的这个错误
^ roundoff.cpp:在函数“int round(double)”中: roundoff.cpp:22:24:错误:新声明'int round(double)' 整数舍入(双倍数字) ^ 在/usr/include/features.h:374:0中包含的文件中, 从/usr/include/x86_64-linux-gnu/c++/4.8/bits/os_defines.h:39, 从/usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h:426, 从/usr/include/c++/4.8/iostream:38, 来自roundoff.cpp:1: /usr/include/x86_64-linux-gnu/bits/mathcalls.h:309:1:错误:对旧声明“双循环(double)”进行歧义 MATHCALLX(圆形,,(双圆形),(/strong>);C++ 如何解决终端的这个错误,c++,C++,^ roundoff.cpp:在函数“int round(double)”中: roundoff.cpp:22:24:错误:新声明'int round(double)' 整数舍入(双倍数字) ^ 在/usr/include/features.h:374:0中包含的文件中, 从/usr/include/x86_64-linux-gnu/c++/4.8/bits/os_defines.h:39, 从/usr/include/x86_64-linux-gnu/c++/4.8/bits/c++confi
^您必须更改函数的名称
round
,因为cmath
已经定义了一个名为round
的方法,该方法具有相同的签名,从而导致歧义。将名称更改为my\u round(双倍数字)
而不是round
,它将起作用。请格式化您的代码。这样读很难,你看。公正地说,C++允许#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
int round(double number);
int main()
{
double doublevalue;
char ans;
do
{
cout << "Enter the double value:";
cin >> doublevalue;
cout << "Rounded that number is"<<round(doublevalue)<<endl;
cout << "Again?(y/n)";
cin >> ans;
}while(ans=='y' ||ans=='Y');
cout << "End of testing.\n";
return 0;
}
int round(double number)
{
return static_cast<int>(floor(number+0.5));
}
roundoff.cpp:6:24: error: new declaration ‘int round(double)’
int round(double number);
^
In file included from /usr/include/features.h:374:0,
from /usr/include/x86_64-linux-gnu/c++/4.8/bits/os_defines.h:39,
from /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h:426,
from /usr/include/c++/4.8/iostream:38,
from roundoff.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:309:1: error: ambiguates old declaration ‘double round(double)’
__MATHCALLX (round,, (_Mdouble_ __x), (__const__));