Ambiguous symbol error?

39,722

Solution 1

Your variable max conflicts with std::max(). Try using a different name and it ought to fix that error.

Solution 2

I think the problem is not std::max() but these horrible #define's in minwindef.h:

#ifndef NOMINMAX
  #ifndef max
  #define max(a,b)            (((a) > (b)) ? (a) : (b))
  #endif
  #ifndef min
  #define min(a,b)            (((a) < (b)) ? (a) : (b))
  #endif
  #endif  /* NOMINMAX */

Use #define NOMINMAX in your project settings or stdafx.h.

Share:
39,722
Haxify
Author by

Haxify

Updated on September 10, 2020

Comments

  • Haxify
    Haxify about 3 years
    int ii, maxnum;  
    for(ii=1; ii<=num-1; ii++) {  
        if(count[ii]>max) {  // the part where I get C2872 Ambiguous Symbol error  
            max = count[ii]; // the part where I get C2872 Ambiguous Symbol error  
            maxnum = ii;  
        }  
    }  
    

    I've never gotten this error and this is frustrating.

  • Andrew Marshall
    Andrew Marshall over 11 years
    It's reasons like this that make using namespace std; such a nightmare.
  • David Rodríguez - dribeas
    David Rodríguez - dribeas over 11 years
    Rather than renaming max I would advice not to use the using directive using namespace std; for exactly this reason.
  • outmind
    outmind over 10 years
    or explicitly define the namespace of max (::max)