-1

here is my function,max is global;

#include<iostream>
using namespace std;

int max = 0;
int q = 0;

int func(int a[], int n)
{  
     int k = 1;
    for(int j = q + 1; j < n; j++)
    {
        if(a[j] <= a[j - 1])
        {
            if(k >= max)
            {
                max = k;
                q = j;
            }
            return 0;
       }
        k++;    
    }

    if(k > max)
    {
        max = k;
        return 1;
    }
}

Here it gives the error that it's ambiguous to compare k with max. Is it because of max being global?

Raindrop7
  • 3,889
  • 3
  • 16
  • 27
zev
  • 33
  • 1
  • 3

1 Answers1

3

It is because you are using std namespace:

using namespace std;

And there is already an std::max which conflicts with your variable max.

16tons
  • 675
  • 5
  • 14
  • so max here is a keyword and can't be used as a variable name? – zev Jan 31 '17 at 10:18
  • no it is not a keyword in C++ language. It is something defined in standard library. So only when you include `namespace std` along with your local variable `max`, the ambiguity arises. – 16tons Jan 31 '17 at 17:00