Close
Close

if i replace MAX with max code doesnt work. Please tell why

   ddc123

#include<iostream>
using namespace std;
const int MAX = 5;
class Search{
private:    int count;
int a[MAX];
    public:
        Search();
        int ser(int item);
        void ins(int item);
};
Search ::Search()
{
    count=0;
    for(int i=0;i<MAX;i++)
    a[i]=0;
}
void Search::ins(int item)
{
    if(count<MAX)
    a[count++]=item;
    else
    cout<<"Array full \n";
}
int Search::ser(int item)
{
    int i;
    
        for(i=0;i<count;i++)
        {
        
        if(a[i]==item)
        break;
    }
    
    if(i==count)
    return -1;
    else 
    return i;
    
    }
    int main()
    {
        int n;
        Search s;s.ins(1),s.ins(23);s.ins(21);s.ins(22);
        cout<<"\n Enter Item to be Inserted :";
        cin>>n;
        s.ins(n);
        cout<<"\n Enter Item to be Searched :";
        cin>>n;
        int i=s.ser(n);
        if(i==-1)
        cout<<"\n Item not found\n";
        else
        cout<<"\n Item found at location "<<i+1;
        
    }

  • Reason main.cpp:7:11: error: reference to 'max' is ambiguous Token max is also defined at bits\stl_algobase.h:260:5: note: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare) max(const _Tp& __a, const _Tp& __b, _Compare __comp)
    - Druva CH

Answers

Ask Yours
Post Yours
Write your answer