Compiler Error C2872

'symbol' : ambiguous symbol

The compiler cannot determine which symbol you are referring to. More than one symbol with the specified name is in scope. See the notes following the error message for the file locations and declarations the compiler found for the ambiguous symbol. To fix this issue, you can fully qualify the ambiguous symbol by using its namespace, for example, std::byte or ::byte. You can also use a namespace alias to give an included namespace a convenient short name for use when disambiguating symbols in your source code.

C2872 can occur if a header file includes a using directive, and a subsequent header file is included that contains a type that is also in the namespace specified in the using directive. Specify a using directive only after all your header files are specified with #include.

For more information about C2872, see Knowledge Base articles PRB: Compiler Errors When You Use #import with XML in Visual C++ .NET and "Error C2872: 'Platform' : ambiguous symbol" error message when you use the Windows::Foundation::Metadata namespace in Visual Studio 2013.


The following sample generates C2872, because an ambiguous reference is made to a variable named i; two variables with the same name are in scope:

// C2872.cpp  
// compile with: cl /EHsc C2872.cpp  
namespace A {  
   int i;  

using namespace A;  
int i;  
int main() {  
   ::i++;   // ok, uses i from global namespace  
   A::i++;   // ok, uses i from namespace A  
   i++;   // C2872 ambiguous: ::i or A::i? 
   // To fix this issue, use the fully qualified name
   // for the intended variable.