c++ - Operator Error in Visual Studio (error C2784) -


i having problem of operators. operators in search , deleteword. in search i'm trying check word in list matches search word. in deleteword i'm trying check word want delete matches word in list , delete it.

i've looked how fix operator don't understand. thank in advance.

some errors:

error 1 error c2784: 'bool std::opeator >=(const std::basic_string<_elem,_traits,_alloc> &,const_elem*): not deduce template argument 'const_elem*' 'const linkedlist'

error 2 error c2784: 'bool std::operator >=(const _elem *,const std::basic_string<_elem,_traits,_alloc> &)' : not deduce template argument 'const _elem *' 'std::string'

error 3 error c2784: 'bool std::operator >=(const std::basic_string<_elem,_traits,_alloc> &,const std::basic_string<_elem,_traits,_alloc> &)' : not deduce template argument 'const std::basic_string<_elem,_traits,_alloc> &' 'const linkedlist'

error 29 error c2678: binary '==' : no operator found takes left-hand operand of type 'std::string' (or there no acceptable conversion)

error 59 intellisense: no operator "==" matches these operands

#ifndef linkedlist_h #define linkedlist_h #include <string> #include <iostream>  using namespace std;  //definition of node struct linkedlist{ //linked list     string word;  //node holds string word     linkedlist *next; //points next node     linkedlist *prev; //points prev node };  class linkedlist{     public:         linkedlist(); //default const         ~linkedlist(); //destructor         const linkedlist& operator = (const linkedlist &); //overload assignment operator         void initializelist(); //func init list empty state         void read();         void printforward(linkedlist *firstword);         void printbackward(linkedlist *lastword);         void insert();         bool search(const linkedlist& searchitem) const;          void deleteword(const linkedlist& deleteitem);          void clear();     protected:         int count;         linkedlist *firstword; //pointer first node         linkedlist *lastword; //pointer last node };  linkedlist::linkedlist() {     firstword = null;     lastword = null;     count = 0; } ... ... //more code ... bool linkedlist::search(const linkedlist& searchitem) const {     bool found = false;      linkedlist *temp; //pointer traverse list     temp = firstword;      while (temp != null && !found)         if (temp->word >= searchitem)             found = true;         else             temp = temp->next;     if (found)         found = (temp->word == searchitem); //test equality     return found;    }  void linkedlist::deleteword(const linkedlist& deleteitem)  {     linkedlist *temp; //pointer traverse list     linkedlist *trailtemp; ///pointer before temp     bool found;      if (firstword == null)         cout << "cannot delete empty list." << endl;     else if (firstword->word == deleteword){ //node deleted firstword         temp = firstword;         firstword = firstword->next;          if (firstword != null)             firstword->prev = null;          else             lastword = null;          count--;         delete temp;     }     else{         found = false;         temp = firstword;          while (temp !=null && !found) //search list             if (temp->word >= deleteword)                 found = true;             else                 temp = temp->next;          if (temp == null)             cout << "the word deleted not in list." << endl;         else if (temp->word == deleteword){ //check equality             trailtemp = temp->prev;             trailtemp->next = temp->next;              if (temp->next != null)                 temp->next->prev = trailtemp;              if (temp == lastword)                 lastword = trailtemp;              count--;             delete temp;         }         else             cout << "the word deleted not in list." << endl;     } } ... ... //more code  ... #endif 

this line:

if (temp->word >= searchitem) 

is comparing std::string linkedlist. want compare word in temp string.

change function to:

bool linkedlist::search(const std::string& searchitem) const 

most of other errors variations on theme.

edit: mistook linkedlist linkedlist - please don't have struct , class same name different cases. confusing.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -