[英]C2678 binary '==': no operator found which takes a left-hand operand of type 'Card' (or there is no acceptable conversion)
I am getting the above error caused by the tie break function 我收到由抢七局引起的上述错误
#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;
}
From what i understand the error means that i am trying to change a const variable. 根据我的理解,该错误意味着我正在尝试更改const变量。 What I don't understand is how I am changing a const variable?
我不明白的是我如何更改const变量?
Help greatly appreciated. 帮助极大的赞赏。
You are calling find
on a vector of Card
s with the integer 2
. 您正在调用
Card
的向量(整数为2
上的find
。 You are getting that error because 2
is not a Card
, nor is there any constructor for Card
that takes one integer parameter that can be used (either there is none, or the one that exists is marked explicit
). 你得到的是错误的,因为
2
是不是Card
,也没有任何构造Card
是采用可以使用一个整型参数(无论有没有,或者说存在一个被标记explicit
)。
You need to clarify (to the compiler) what it is your looking for. 您需要(向编译器)说明您要寻找的内容。 What is
Card
2? 什么是
Card
2?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.