Compiler Error C2872 产生错误的研究

在公司的程序中遇到Compiler Error C2872,该错误表明编译器无法确定引用的符号。通过查阅MSDN,了解到此错误通常是由于符号歧义导致。为了解决这个问题,需要深入分析代码并消除可能的命名冲突。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

公司里的一个程序,出现了Compiler Error C2872 错误,怎么调试也不行。从网上找来了一部分资料,

先可以看看MSDN的解释:

'symbol' : ambiguous symbol

The compiler could not determine which symbol you are referring to.

The following code shows an example of this error.

namespace A {
   int i;
}

using namespace A;

int i;

void z() {
   ::i++;   // ok
   A::i++;   // ok
   i++;      // error C2872, ::i or A::i?
}
意思好象是命名空间出了问题。网上有一个例子:

  
   

EXAMPLE 2: The following sample causes compiler error C2872 'symbol' : ambiguous symbol

	//Compile options: /GX
	#pragma warning (disable : 4786)

	#include &ltiostream.h>
	#include &ltiostream>

	using namespace std ;

	int main()
	{
		cout << "Hello World" << endl ; //C2872 here
		return 0 ;
	}

To workaround this problem, remove the using namespace directive. If you remove the using directive the cout from the old iostream is used. To use cout from the Standard C++ Library use fully qualified names for example, std::cout.

<script language="JavaScript" src="MS-ITS:dsmsdn.chm::/html/msdn_footer.js" type="text/javascript"> </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值