COMPILER ERROR C2872 Generation Error Research

xiaoxiao2021-03-05  31

A program in the company, there is a compiler Error C2872 error, how to debug can't. I have found some information from the Internet.

First look at MSDN explanation:

'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?

}

Means is a problem with namespace. There is an example on the Internet:

Example 2: The Following Sample Causes Compiler Error C2872 'Symbol': Ambiguous Symbol // Compile Options: / GX

#pragma Warning (Disable: 4786)

#include & ltioostream.h>

#include & ltioostream>

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.