Reputation: 49
I am getting this error while compiling this program. This questions is to find max of min's window size. Here is my code:
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for(int i=0; i<n; i++)
{
cin>>a[i];//to take input as array
}
for(int k=1; k<=n; k++)
{
int max=0;
for(int i=0; i<n-k; i++)
{
int min=a[i];
for(int j=0; j<k; j++)
{
if(a[i+j]<min)
{
min=a[i+j];
}
}
}
if(min > max)
{
max=min;
}
cout<<max<<" ";
}
return 0;
}
Upvotes: 3
Views: 5482
Reputation: 92261
You are hiding (shadowing) the std::min
and std::max
functions by the local declarations of int max
and int min
. However, this shadowing only happens in the local scope, where these variables are declared.
When you leave the scope, the outer name becomes visible again:
int max=0; // <-- Here max hides std::max
for(int i=0; i<n-k; i++)
{
int min=a[i]; // <-- Here min hides std::min
for(int j=0; j<k; j++)
{
if(a[i+j]<min)
{
min=a[i+j];
}
}
} // <-- But here the local min goes away again
if(min > max) // <-- And here min is std::min, a function
So the compiler believes that min > max
is to compare an int
to a function template. And it cannot see how to do that.
This is one of the reasons why using using namespace std;
is considered not a good idea.
Upvotes: 5