0

I am creating a simple c++ texas hold'em but have encountered a problem in a function which is part of a class. When i use variables from the class in the function in the class it comes out as Undefined reference to "class::variable" for my 4 static variables in classes. Here is the code with the concerned part:

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

class Player{
    static string cards[53];
    static string final_card1[6];
    static string final_card2[6];
    static string table_cards[5];

    public:
    string set_cards(int c){return cards[c];}
    void set_final_card(int i, int max_i);
};

void Player::set_final_card(int i, int max_i){
    int tempV = 17;//create temp cards
    string tempCards[tempV];

    int rand_nb[tempV];//Create distinct random numbers
    bool check1 = false;
    while (check1==false){
        for(int p=0; p<tempV;p++){

            tempCards[p]=cards[rand()%53];
            check1=true;
            for(int o=(p-1); o!=0; o--){
                if (tempCards[p]==tempCards[o]){
                  check1=false;
                }
            }

        }

    }
    int p=0,k;
    while(p<6){
        k=0;
        final_card1[k]=tempCards[p];
        k++;
    }
    while(p<12){
        k=0;
        final_card2[k]=tempCards[p];
        k++;
    }
    while(p<17){
        k=0;
        table_cards[k]=tempCards[p];
        k++;
    }
}

The function is declared in int main() after the objects are created. The objects are player[i]. If you believe the probleme might be from elsewhere ask and I will post full code.

Thanks for feedback

Yoan Poulmarc'k
  • 33
  • 2
  • 11
  • Please **[edit]** your question with a [mcve] or [SSCCE (Short, Self Contained, Correct Example)](http://sscce.org) – NathanOliver Oct 12 '16 at 11:49
  • You need to provide out-of-line definitions for all the static variables. I would suggest not using static members for this purpose. – M.M Oct 12 '16 at 11:50

0 Answers0