2014-01-08 102 views
0

我收到了這個惱人的錯誤C2678:二進制'>':找不到操作符需要左手操作數。 我想使用find_if找到除數和由迭代器返回的值添加到向量中。 我會很感激任何想法。錯誤C2678:二進制'>':沒有找到左手操作數的操作符

頭文件

#ifndef SMTH_H 
#define SMTH_H 


#include <vector> 
#include <iostream> 

    using namespace std; 

    using std::vector; 

    namespace Calculator{ 
     namespace Cal{ 

      typedef unsigned int Uint; 
      typedef vector<Uint> TVint; 
      typedef vector<Uint>::const_iterator TIterator; 
    /..../ 

     class TestPrim : public Sir 
      { 
      protected: 
       Uint _val;  
       double _stopVal; 

      public: 
       Uint testPrim; 
       TestPrim(Uint val); 
       TestPrim& operator ++(); 
       bool operator() (Uint divizor); 
       operator Uint(); 
       friend bool operator > (Uint val, const TestPrim &src); 

      }; 
     } 
    } 
    #endif 

cpp文件

#include <iomanip> 
#include "smth.h" 
#include <iostream> 
#include <algorithm> 
#include <vector> 

using namespace std; 

namespace Calculator{ 
    namespace Cal{ 
/..../ 

class TestPrim; 

     void Prime::CalculeazaValori(int index) 
     { 
      if(index > MAX_PRIME) 
      { 
       throw errorCheck(); 
      } 

      if(index == 0) 
      { 
       _elemente.push_back(2); 
       _elemente.push_back(3); 
      } 

      for (TestPrim testPrim = (_elemente.back() + 2); _elemente.size() < _count; ++testPrim) 
      { 

       TIterator it = find_if (_elemente.begin(), _elemente.end(), testPrim ); 
       if (it > testPrim) //error on this line 
       { 
        _elemente.push_back(testPrim); 
       } 
      } 
     } 



    } 
} 
+1

請不要**在使用指令或聲明在頭。當我添加標題時,我不希望帶來額外的垃圾。 – chris

+0

@chris我會記住。謝謝! – Zodrak

回答

1

這是你的操作是什麼樣子:

friend bool operator > (Uint val, const TestPrim &src); 

,這是你如何使用它:

it > testPrim 

itTIterator,而不是Uint。想必你的意思是

*it > testPrim 
+0

你真棒!非常感謝你!有用 – Zodrak

相關問題