实际上这段代码在“DEV C++”中运行良好,但当我将其放入我的“Hacker-Rank”面板时,它会出现“reference to function is ambiguous”的错误,尽管所有在线编译器都会出错...
我认为这里函数重载并没有干扰任何地方,因为这种错误大多发生在函数重载中。
#include <bits/stdc++.h>
#include <cstdio>
#include<iostream>
using namespace std;
int function(int n);
int main()
{
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
if(n<=0){
return(0);
}
else{
function(n);
}
}
int function(int n)
{
if (n<=9)
{
cout<<"experiment";
}
else{
cout<<"Greater than 9";
}
return 0;
}
<source>:20:9: error: reference to 'function' is ambiguous
function(n);
^
<source>:8:5: note: candidate found by name lookup is 'function'
int function(int n);
^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/11.0.0/../../../../include/c++/11.0.0/bits/std_function.h:111:11: note: candidate found by name lookup is 'std::function'
class function;
^
// ... and more ....
using namespace std;
。 - molbdnilo<bits/stdc++.h>
,那么为什么还要包含其他头文件呢? - Arsenic