0

I need a way to access static 2D vector in my static function. The reason being I want to use syntax like GameBoard::initBoard() in my main() function.Observe the following code snippets. I have higlighted error in comments

GameBoard Header

class GameBoard
{
    public:
        static void initBoard();


    protected:

    private:
        static std::vector <std::vector<char>> chessBoard;
};

InitBoard implementation is as follows

void GameBoard::initBoard()
{
    std::vector<char> blankPos {'.','.','.','.','.','.','.','.'};
    for(int i{0}; i < 8; i++)
    {
        chessBoard.push_back(blankPos);       //getting Error here
    }

}

The error shown is:

undefined reference to `GameBoard::chessBoard'

Parag
  • 55
  • 6
  • 1
    In the class you only *declare* the static member variable `chessBoard`, you need to *define* it as well. Any decent [book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282), class or tutorial should have an explanation about this. As would millions of examples all over the greater Internet, of which many thousands of them would be here on stackoverflow.com. – Some programmer dude Feb 05 '20 at 13:16
  • Thanks for the info!! that worked like a charm!! – Parag Feb 05 '20 at 15:03

0 Answers0