简体   繁体   English

C2678二进制'==':找不到使用'Card'类型的左操作数的运算符(或者没有可接受的转换)

[英]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.

相关问题 错误C2678:二进制'==':找不到哪个运算符采用类型的左操作数(或者没有可接受的转换) - error C2678: binary '==' : no operator found which takes a left-hand operand of type (or there is no acceptable conversion) 错误1错误C2678:二进制&#39;!=&#39;:未找到采用&#39;std :: ofstream&#39;类型的左操作数的运算符(或没有可接受的转换) - Error 1 error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::ofstream' (or there is no acceptable conversion) 错误 C2678:二进制“=”:未找到采用“const std::string”类型的左操作数的运算符(或没有可接受的转换) - error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion) 错误C2678:二进制'<<':找不到运算符,它接受类型为'const std :: ofstream'的左手操作数(或者没有可接受的转换) - Error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'const std::ofstream' (or there is no acceptable conversion) 错误C2678:二进制&#39;+&#39;:未找到采用&#39;volatile A&#39;类型的左操作数的运算符(或者没有可接受的转换) - error C2678: binary '+': no operator found which takes a left-hand operand of type 'volatile A' (or there is no acceptable conversion) 错误C2678:二进制&#39;&gt;&gt;&#39;:未找到采用&#39;std :: istream&#39;类型的左操作数的运算符(或没有可接受的转换) - error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion) 错误C2678:二进制'=':找不到哪个运算符带有'const Recipe'类型的左手操作数(或者没有可接受的转换) - error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const Recipe' (or there is no acceptable conversion) 错误 C2678:找不到采用“const_Ty”类型的左侧操作数的运算符(或没有可接受的转换) - error C2678: no operator found which takes a left-hand operand of type 'const_Ty' (or there is no acceptable conversion) 错误C2678:二进制&#39;&gt;&gt;&#39;:未找到采用&#39;std :: stringstream类型的左操作数的运算符 - error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::stringstream c2678 二进制“==”未找到采用左侧操作数类型的运算符 - c2678 binary '==' no operator found which takes a left-hand operand of type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM