C2678 二进制 '==':未找到采用 'Card' 类型左操作数的运算符(或者没有可接受的转换)
C2678 binary '==': no operator found which takes a left-hand operand of type 'Card' (or there is no acceptable conversion)
我收到由领带中断函数引起的上述错误
#include <vector>
#include <iostream>
#include <algorithm>
class Hand{
private:
std::vector<Card> cards;
public:
PokerHand(Card c1, Card c2) {
cards.push_back(c1);
cards.push_back(c2);
cards.push_back(c3);
cards.push_back(c4);
cards.push_back(c5);
}
bool breakTie(const PokerHand& other) const{
std::vector<Card> temp1 = { cards };
std::vector<Card> temp2 = { other.getCards()};
return std::find(temp1.begin(), temp1.end(), 2) < std::find(temp2.begin(), temp2.end(), 2)
}
std::vector<Card> getCards(){
return cards;
}
};
class Card{
private:
int value;
public:
bool operator ==(const Card& right)const {
return (this->value == right.getValue());
}
int getValue(){
return value;
}
Card(int value){
this->value=value;
}
};
int main(){
Card a(4);
Card b(5);
Hand hand(a,b);
hand.breakTie();
return 0;
}
据我了解,该错误意味着我正在尝试更改 const 变量。我不明白的是我是如何更改常量变量的?
非常感谢帮助。
您正在使用整数2
在Card
s 的向量上调用find
。 您收到该错误是因为2
不是Card
,也没有任何Card
的构造函数采用一个可以使用的整数参数(要么没有,要么存在的构造函数标记为explicit
(。
你需要澄清(向编译器(你在寻找什么。 什么是Card
2?
相关文章:
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- C2678 二进制 '==':未找到采用 'Card' 类型左操作数的运算符(或者没有可接受的转换)
- 二进制 '==':未找到采用 'Enemy' 类型左侧操作数的运算符(或者没有可接受的转换)
- 二进制 '=':未找到采用右操作数的运算符(或者没有可接受的对话)
- 错误 C2679:二进制'<<':找不到采用类型 'overloaded-function' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误:C2679 二进制"==":未找到采用类型 'const std::string' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2678:二进制"+":未找到采用类型 'volatile A' 的左侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制"<<":未找到采用类型 'mystring' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制'>':找不到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679 二进制"=":未找到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679 二进制"=":未找到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- 运算符重载:简单添加...错误 C2677:二进制"+":未找到采用类型 ___ 的全局运算符(或者不存在可接受的转换)
- 错误 C2677:二进制'+=':找不到采用类型 'Movie' 的全局运算符(或者没有可接受的转换)
- 错误 C2678:'=='二进制:未找到采用类型 'CSchemaString' 的左操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制"[":未找到采用类型为"const VerseKey"的右操作数的运算符(或者没有可接受的转换)
- 错误 C2678:二进制"==":找不到采用左操作数类型的运算符(或者没有可接受的转换)
- 错误 1 错误 C2679:二进制'<<':未找到采用类型 'rational' 的右侧操作数的运算符(或者没有可接受的转换)
- 二进制'operator':未找到采用类型为 'Fraction' 的右操作数的运算符(或者没有可接受的转换)
- 错误 C++ 2679(二进制">>":未找到采用类型 'const std::string' 的右侧操作数的运算符(或者没有可接受的转换))
- 二进制'operator':没有定义采用 'type' 型左操作数的运算符(或者没有可接受的转换)