Visual Studio中的操作员错误(错误C2784)
Operator Error in Visual Studio (error C2784)
我的一些运算符有问题。我搜索和删除Word中的运算符。在搜索中,我试图检查列表中的单词是否与搜索单词匹配。在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::string"推导出"const_Elem*"的模板参数
错误3错误C2784:"bool std::operator>=(const std::basic_string<_Elem,_Traits,_Alloc>&,const std::basic_strong<_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)
正在将CCD_ 1与CCD_。您要将temp
中的word
与字符串进行比较。
将功能更改为:
bool LinkedList::search(const std::string& searchItem) const
你的大多数其他错误都是这个主题的变体。
编辑:将LinkedList
误认为linkedList
-请不要有名称相同但大小写不同的结构和类。这很令人困惑。
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- C++ -- 错误 C2784: -- 请参阅'std::operator <<'声明
- 对向量 OS 字符串进行排序 C++ 错误 C2784 无法推断模板参数
- 视觉工作室错误 C2784
- 表达式模板:错误 C2784 'could not deduce template argument'
- C++错误代码C2784无法推导的模板参数
- 我的二进制搜索树 c++ 的递归函数中的错误 C2784 无法推断模板参数
- Visual Studio中的操作员错误(错误C2784)
- 错误C2784, C2672和C2664在Visual studio 2015
- 为什么此代码有 C2784 "could not deduce template argument"错误
- 算法文件解决方案中的c2784, c2780和c2676错误
- C:错误 C2784:'bool std::运算符<