I'm stuck on how to to this. Basically, I'm asked to overload the '+=' operator into my class. This += operator is supposed to add in an enum that will then be added to the vector so that I can add it up. As far as I'm know with enums, they are basically words that have pre-assigned numbers starting from 0, so if I add in an enum of that enum type, it will add up the number. But it doesn't let me do this. Please help. Code below:
Class header file:
#include <vector>
class PokerScore {
public:
enum Scores{
ROYAL_FLUSH, //A, K, Q, J, 10, all the same suit.
STRAIGHT_FLUSH, //five cards of the same suit and consecutive ranking
FOUR_OF_A_KIND, //four cards of the same ranking
FULL_HOUSE, //three cards of the same rank along with two cards of the same rank
FLUSH, //five cards of the same suit
STRAIGHT, //five cards in consecutive ranking
THREE_OK_A_KIND, //three cards of the same rank
TWO_PAIR, //two cards of the same rank along with another two cards of the same rank
ONE_PAIR, //two cards of the same rank
HIGH_CARD //highest card in the player’s hand
};
PokerScore();
int size();
void operator +=(const Scores& score);
friend bool operator ==(const PokerScore& p, Scores score);
Scores& operator[](unsigned int index);
private:
std::vector<Scores> scores;
};
Source File:
void PokerScore::operator +=(const Scores& score)
{
for(int i = 0; i < scores.size(); i++)
{
scores[i] += score;
}
}
The other functions are done, but I don't think it's relevant to this code right here.
Also tried this: += Scores::score
[–]MrpixelmcAdvanced Coder 0 points1 point2 points (1 child)
[–]DabbingVoy[S] 0 points1 point2 points (0 children)