我收到編譯錯誤,說'左'和'右'不明確。編譯錯誤:左邊模糊不清,右邊模糊
我是否宣佈左,右對錯?
- 內主聲明並沒有幫助
- 移動上述主要功能的定義並不能幫助
如何我會解決這個問題?
最少測試用例:
#include <iostream>
using namespace std;
int left = 0, right = 0;
int main()
{
cout << left;
cout << right;
}
所賜:
prog.cpp: In function ‘int main()’:
prog.cpp:6:13: error: reference to ‘left’ is ambiguous
prog.cpp:3:5: error: candidates are: int left
In file included from /usr/include/c++/4.7/ios:43:0,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from prog.cpp:1:
/usr/include/c++/4.7/bits/ios_base.h:918:3: error:
std::ios_base& std::left(std::ios_base&)
prog.cpp:7:13: error: reference to ‘right’ is ambiguous
prog.cpp:3:15: error: candidates are: int right
In file included from /usr/include/c++/4.7/ios:43:0,
from /usr/include/c++/4.7/ostream:40,
from /usr/include/c++/4.7/iostream:40,
from prog.cpp:1:
/usr/include/c++/4.7/bits/ios_base.h:926:3: error:
std::ios_base& std::right(std::ios_base&)
對未來的建議 - 構建[最小測試用例](https://ideone.com/c2DqtQ)並將代碼粘貼到問題中,而不僅僅是指向它的鏈接。 – Dukeling 2013-03-20 06:30:06
我只是無法理解此網站上的代碼格式! – user1776433 2013-03-20 06:36:54
現在你知道你爲什麼不使用'namespace std;'! – 2013-03-20 06:36:58