2017-05-14 49 views
0

また、エラーがヘッダファイルpredefined_ops.hに表示され、私はコードブロックに次のコードをコンパイルしていると私は次のエラーの文C++エラーを理解するには、「演算子== '(オペランドの型は' std :: pair 'と' const int ')」と一致しません。

C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\predefined_ops.h|191|error: no match for 'operator==' (operand types are 'std::pair' and 'const int')

を得る:

template<typename _Iterator> 
    bool 
    operator()(_Iterator __it) 
    { return *__it == _M_value; }//error 
    }; 

これは私がコンパイルしていたコードです

#include <bits/stdc++.h> 
using namespace std; 
class Soham 
{ 
    int *a,n; 
    map<int,int> m; 
public: 
    Soham(int x); 
    void search1(int,int,int,int); 
}; 
Soham::Soham(int x) 
{ 
    n=x; 
    a=new int[n]; 
    for(int i=0;i<n;i++) 
     cin>>a[i]; 
    for(int i=0;i<n;i++) 
    { 
     for(int j=i+1;j<n;j++) 
     { 
      if(abs(a[i]-a[j])<=1) 
       { 
        search1(a[i],a[j],i,j); 
       } 
     } 
    } 
    map<int,int> ::iterator it1; 
    for(it1=m.begin();it1!=m.end();it1++) 
    { 
     cout<<it1->first<<"-->"<<it1->second<<endl; 
    } 
} 
void Soham::search1(int x,int y,int i1,int j1) 
{ 
    if(m.empty()) 
    { 
     m.insert(std::pair<int,int>(x,i1)); 
     m.insert(std::pair<int,int>(y,j1)); 
    } 
    else 
    { 
     map<int,int>::iterator it,it1; 
     it=find(m.begin(),m.end(),x); 
     it1=find(m.begin(),m.end(),y); 
     if(it!=m.end()|| it1!=m.end()) 
     { 

      if (it!=m.end() && it->second!=i1)//chance of error 
       { 
        m.insert(std::pair<int,int>(it->first,i1)); 
       } 


       if(it1!=m.end() && it1->second!=j1)//chance of error 
      { 
        m.insert(std::pair<int,int>(it1->first,j1)); 
      } 


     } 
     //find failed to find element in the map how to show this particular condition 
     else //error 
     { 
      if(it!=m.end()) 
      { 
       m.insert(std::pair<int,int>(x,i1)); 
      } 
      if(it1!=m.end()) 
      { 
       m.insert(std::pair<int,int>(y,j1)); 
      } 

     } 
    } 

} 
int main() 
{ 
    int n; 
    cin>>n; 
    Soham a(n); 
    return 0; 
} 

エラー文ごとに、==演算子を使用して無効な比較を行っていますが、トンおそらくエラーが私はint型であるペア(IT->秒)の2番目の要素をチェックしています第2チェックでは、以下の条件に

if (it!=m.end() && it->second!=i1) 
if(it1!=m.end() && it1->second!=j1) 

を発生する場所これは それゲットします整数変数i1の場合、==演算子でエラーが発生するのはなぜですか?私は間違った方法でエラーを理解している可能性があり、そうでない場合、私の理解を説明しているかもしれません。何がエラーを生成し、それを修正する方法?

+0

[C++ STL:std :: find with std :: map]の可能な複製(http://stackoverflow.com/questions/42485829/c-stl-stdfind-with-stdmap) – Shibli

+0

"チェーン"(おそらく" ... ...インスタンス化された "と言っています)、コンパイラは最終的に問題が' find'行にあると伝えます。テンプレートのエラーメッセージをナビゲートすることは、最善のときに困難になる可能性があります。 – molbdnilo

答えて

0

を変更し、次の行、それは基本的にあなたがfindメンバ関数の代わりに、 findアルゴリズムを使用する必要が

//it=find(m.begin(),m.end(),x); 
    it = m.find(x); 
    //it1=find(m.begin(),m.end(),y); 
    it1 = m.find(y); 

を実行します。

+0

問題を明確にしてくれてありがとうPartha :) – jack121

関連する問題