dimanche 14 octobre 2018

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, through searching i believe that it is cause by the following function.

bool breakTie(const PokerHand& other) const{
   std::vector<Card> temp1 = { cards };
   std::vector<Card> temp2 = { other.getCards()};
   std::sort(temp1.begin(), temp1.end());
   std::sort(temp2.begin(), temp2.end());
   //2,3,4,5,6,7,8,9,10,j,q,k,a
   std::vector<int> counts = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

  for (auto el : cards) {
      counts[el.getValue() - 2]++;
  }
  //flush tie
  if (determineHand() == static_cast<int>(combos::flush)) {       
      for (int i = cards.size() - 1; i >= 0; i--) {
          if (temp1[i].getValue() < temp2[i].getValue()) {
              return true;
          }
          else if (temp1[i].getValue() > temp2[i].getValue()) {
              return false;
          }
      }
  }
  //royal flush
  if (determineHand() == static_cast<int>(combos::royalFlush)) {
      return true; //behavior not defined by teacher or game rules
  }
  //2pair tie
  if (determineHand() >= static_cast<int>(combos::twoPair3) && determineHand() < static_cast<int>(combos::twoPairA)) {
      if (std::find(temp1.begin(), temp1.end(), 2) < std::find(temp2.begin(), temp2.end(), 2)) {
          return true;
      }
      else if (std::find(temp1.begin(), temp1.end(), 2) > std::find(temp2.begin(), temp2.end(), 2)) {
          return false;
      }
      else {
          for (int i = temp1.size() - 1; i >= 0; i--) {
              if (temp1[i].getValue() < temp2[i].getValue()) {
                  return true;
              }
              else if (temp1[i].getValue() > temp2[i].getValue()) {
                  return false;
              }
          }
      }
  }
  else if (determineHand() >= static_cast<int>(combos::pair2) && determineHand() <= static_cast<int>(combos::pairA)) {
      for (int i = temp1.size() - 1; i >= 0; i--) {
          if (temp1[i].getValue() < temp2[i].getValue()) {
              return true;
          }
          else if (temp1[i].getValue() > temp2[i].getValue()) {
              return false;
          }
      }
  }
  return true;

} I believe the line that is causing the error is if (std::find(temp1.begin(), temp1.end(), 2) < std::find(temp2.begin(), temp2.end(), 2)) { under the 2pair comment

From what i understand the error means that i am trying to change a const variable. What I don't understand is how I am changing a const variable?

Help greatly appreciated.

Also the following are my operator overloading in the card class

bool operator <(const Card& right) const {
  return this->getValue() < right.getValue();
}
bool operator ==(const Card& right)const {
  return (this->getValue() == right.getValue());
}

Aucun commentaire:

Enregistrer un commentaire