當我試圖編譯這段代碼編譯錯誤
using namespace std;
namespace asf{
inline int operator|(int);
}
asf::operator|(int x){
return (x>1)?x*operator|(x-1):1;
}
int main(){
cout<<5|;
}
我收到以下錯誤
[Error] 'int asf::operator|(int)' must have an argument of class or enumerated type
[Error] ISO C++ forbids declaration of 'operator|' with no type [-fpermissive]
[Error] 'int asf::operator|(int)' should have been declared inside 'asf'
[Error] 'int asf::operator|(int)' must have an argument of class or enumerated type
In function 'int main()':
[Error] expected primary-expression before ';' token
有什麼不對?請幫忙。
你不能在'int'上重載'|'。另外,'|'是一個二元運算符。 – Shahbaz