![](/img/trans.png)
[英]why the error : “reference to fixes is ambiguous” is occurring in the code?
[英]why does the following code generate a "reference to 'tm' is ambiguous" error?
#include <iostream>
using namespace std;
namespace characters {
char tm='a';
char tc='a';
}
using namespace characters;
class table {
public:
void printline (){
char m;
m=tm;
//m=tc;
cout<<m<<m<<m<<m<<m<<m<<m<<m<<m;
}
};
int main()
{
table myTable;
myTable.printline();
return 0;
}
但是當你注釋掉 m=tm; 行並恢復行 m=tc 代碼工作正常。
標識符 tm 有什么特別之處?
using namespace characters;
是將characters::tm
帶入全局命名空間並與全局struct tm
產生歧義的問題。 解決方案:
// using namespace characters;
using characters::tm;
這會指示編譯器,如果遇到tm
,請在此處使用命名空間characters
中的tm
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.