У меня проблема с некоторыми из моих операторов. Операторы в моем поиске и deleteWord. В поиске я пытаюсь проверить, что слово в моем списке соответствует поисковому слову. В deleteWord я пытаюсь проверить, что слово, которое я хочу удалить, отлично совпадает со словом в моем списке, а затем удаляет его.Ошибка оператора в Visual Studio (ошибка C2784)
Я искал, как исправить мой оператор, но я не понимаю. Заранее спасибо.
Некоторые ошибки:
Ошибка 1 Ошибка C2784: «BOOL станд :: opeator> = (Const станд :: basic_string < _Elem, _Traits, _Alloc> &, const_Elem *): не может вывести аргумент шаблона для 'const_Elem *' для 'сопзЬ LinkedList'
ошибка 2 ошибка C2784: 'BOOL станд :: оператор> = (Const _Elem * Const станд :: basic_string < _Elem, _Traits, _Alloc> &)': не может вывести аргумент шаблона для 'const _Elem *' из 'std :: string'
Ошибка 3 Ошибка C2784: 'BOOL станд :: оператор> = (Const станд :: basic_string < _Elem, _Traits, _Alloc> &, Const станд :: basic_string < _Elem, _Traits, _Alloc> &)': не может вывести шаблон аргумент «сопзЬ станд :: basic_string < _Elem, _Traits, _Alloc> &» от «сопзЬ LinkedList»
ошибка 29 ошибка C2678: бинарный «==»: ни один оператор не найден, который принимает левого операнда типа ' std :: string '(или нет приемлемого преобразования)
Ошибка 59 IntelliSense: оператор «==» не соответствует этим операндам
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <string>
#include <iostream>
using namespace std;
//Definition of the node
struct linkedList{ //linked list
string word; //node holds string word
linkedList *next; //points to next node
linkedList *prev; //points to prev node
};
class LinkedList{
public:
LinkedList(); //default const
~LinkedList(); //destructor
const LinkedList& operator = (const LinkedList &); //overload the assignment operator
void initializeList(); //func to init list to an 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 to the first node
linkedList *lastWord; //pointer to the 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 to 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 for equality
return found;
}
void LinkedList::deleteWord(const LinkedList& deleteItem)
{
linkedList *temp; //pointer to traverse the list
linkedList *trailTemp; ///pointer just before temp
bool found;
if (firstWord == NULL)
cout << "Cannot delete from an empty list." << endl;
else if (firstWord->word == deleteWord){ //node to be deleted is the 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 the list
if (temp->word >= deleteWord)
found = true;
else
temp = temp->next;
if (temp == NULL)
cout << "The word to be deleted is not in the list." << endl;
else if (temp->word == deleteWord){ //check for 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 to be deleted is not in the list." << endl;
}
}
...
... //more code
...
#endif
Какова конкретная ошибка или ошибки, которые вы получаете? –
Вы уверены, что вам нужно вернуть 'const LinkedList &' в качестве возврата 'operator ='? Почему 'const'? И вам не хватает '# endif' в конце. – vsoftco
@RetiredNinja Я добавил некоторые ошибки, которые у меня есть. – Miz