Apologies for my ignorance. I'm relatively new to C++ from another language. I'm making a program to rank poker hands for an assignment and I'm hitting an error that I don't understand but I'm assuming is a major syntax error. Please be nice, I'm trying to learn. This will not build in Xcode. When I try, I get the following error message:
12 Duplicate Symbols for architecture x86_64
I am really confused by this error. Here is my code:
poker.hpp
#ifndef poker_hpp
#define poker_hpp
#include <stdio.h>
#include <iostream>
#include <array>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
const size_t HAND_ARRAY_SIZE = 5;
const size_t CARD_ARRAY_SIZE = 2; //just in case, might not use it
typedef array<string, HAND_ARRAY_SIZE> hand_t; //typedef for poker hands
typedef array<string, CARD_ARRAY_SIZE> card_t; //just in case, might not use it
const size_t SUIT_ARRAY_SIZE = 4;
static array<string, SUIT_ARRAY_SIZE> suits =
{"C", "D", "H", "S"};
const size_t VALUE_ARRAY_SIZE = 13;
static array<string, VALUE_ARRAY_SIZE> ranks_ace_high =
{"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"};
static array<string, VALUE_ARRAY_SIZE> ranks_ace_low =
{"A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"};
const size_t HAND_RANK_ARRAY_SIZE = 10;
//EDIT: added static
static array<string, HAND_RANK_ARRAY_SIZE> handRanks =
{
"high card",
"pair",
"two pair",
"three of a kind",
"straight"
"flush",
"full house",
"four of a kind",
"straight flush",
"royal flush"
};
class Hand {
private:
hand_t cards;
string type();
float value();
bool acesLow();
public:
Hand(hand_t cards);
};
#endif /* poker_hpp */
test_hands.cpp
#include "poker.hpp"
hand_t test0 {"TC", "9C", "8C", "7C", "6C"};
hand_t test1 {"8H", "7H", "6H", "5H", "4H"};
hand_t test2 {"8H", "7H", "6H", "5H", "4H"};
hand_t test3 {"6S", "5S", "4S", "3S", "2S"};
hand_t test4 {"7D", "6D", "5D", "4D", "3D"};
hand_t test5 {"7S", "6S", "5S", "4S", "3S"};
hand_t test6 {"KS", "KH", "KC", "KD", "3H"};
hand_t test7 {"7H", "7D", "7S", "7C", "QH"};
hand_t test8 {"7H", "7D", "7S", "7C", "QH"};
Hand.cpp
#include "poker.hpp"
Hand::Hand(hand_t cards){
this->cards = cards;
}
main.cpp
#include "poker.hpp"
#include "test_hands.cpp"
int main() {
Hand hand(test0);
};