Visual Studio中的操作员错误(错误C2784)

米兹

我的一些操作员有问题。运算符在我的搜索和deleteWord中。在搜索中,我试图检查列表中的单词是否与搜索单词匹配。在deleteWord中,我试图检查要删除的单词是否与列表中的单词完全匹配,然后将其删除。

我一直在寻找如何修复操作员的方法,但我不理解。先感谢您。

一些错误:

错误1错误C2784:'bool std :: opeator> =(const std :: basic_string <_Elem,_Traits,_Alloc>&,const_Elem *):无法为'const LinkedList'推断'const_Elem *'的模板参数

错误2错误C2784:'bool std :: operator> =(const _Elem *,const std :: basic_string <_Elem,_Traits,_Alloc>&)':无法从'std ::推断出'const _Elem *'的模板参数细绳'

错误3错误C2784:'bool std :: operator> =(const std :: basic_string <_Elem,_Traits,_Alloc>&,const std :: basic_string <_Elem,_Traits,_Alloc>&)':无法推导以下模板参数'const std :: basic_string <_Elem,_Traits,_Alloc>&'来自'const 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
黑暗

这行:

if (temp->word >= searchItem)

正在将astd::string进行比较LinkedList您想将wordintemp与一个字符串进行比较

将该函数更改为:

bool LinkedList::search(const std::string& searchItem) const

您的其他大多数错误都是该主题的变体。

编辑:误把LinkedListlinkedList-请不要有一个结构与类别名称相同,但不同的情况。这很令人困惑。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Visual Studio错误C2784

来自分类Dev

Visual Studio错误C2784

来自分类Dev

Visual Studio 2015中出现错误C2784,C2672和C2664

来自分类Dev

Visual Studio中的C ++错误

来自分类Dev

Visual Studio 2015中的C代码错误

来自分类Dev

Visual Studio中的Phalanger错误

来自分类Dev

Visual Studio 中的错误结果

来自分类Dev

在 Visual Studio 中构建错误

来自分类Dev

Visual Studio终端中的CTRL + C在50%的时间内不执行任何操作。错误或功能?

来自分类Dev

Visual Studio中的Python:错误错误

来自分类Dev

Visual Studio Bower错误

来自分类Dev

Visual Studio错误

来自分类Dev

C ++ LInker错误(Visual Studio C ++ 2010)

来自分类Dev

Fortran和C ++:Visual Studio中的链接错误

来自分类Dev

C ++ Visual Studio Express 2012中的舍入错误

来自分类Dev

igraph C在Visual Studio中编译链接错误

来自分类Dev

Visual Studio C ++中的msmpi.dll错误消息

来自分类Dev

Visual Studio Analyzer报告C#代码中的错误

来自分类Dev

C ++ Visual Studio Express 2012中的舍入错误

来自分类Dev

Visual Studio委托中的C#和异常错误

来自分类Dev

在Visual Studio C ++中检测实际的编译错误

来自分类Dev

Visual Studio中的std文件内部错误

来自分类Dev

Visual Studio Community 2015中的SDK错误

来自分类Dev

Visual Studio在TypeScript中显示`this`的值错误

来自分类Dev

WPF Visual Studio Designer中的错误

来自分类Dev

Visual Studio 2013中的FTP发布错误

来自分类Dev

Visual Studio中的OpenCV构建错误

来自分类Dev

无权报告Visual Studio 2015中的错误

来自分类Dev

Visual Studio中的类包含错误