It has been far too long since I have coded anything and I'm stumbling over something that should be obvious. If someone could point me in the right direction I'd greatly appreciate it.
I have:
A "Square" class representing a square on a checker board:
And a "Board" class which is basically just an 2-D array of Squares:Code:class Square { public: Square(int); void print_square(); private: int color; static const char red[3]; static const char black[3]; };
Where I'm having problems is in calling the Square::Square(int) constructor from my Board::Board() constructor:Code:class Board { public: Board(); void print_board(); private: Square board[8][8]; };
When I compile I get:Code:Board::Board () { for ( int row = 0; row < 8; row++ ) for ( int col = 0; col < 8; col++ ) { int temp = (col + row) % 2; Square board[col][row]( temp ); } }
I'm not sure what the problem is. Perhaps I've lost my grasp on how arrays are handled, or maybe its something else.Code:dberg@ubuntu:~/Desktop/Checkers$ g++ -c Board.cpp Board.cpp: In constructor ‘Board::Board()’: Board.cpp:20: error: no matching function for call to ‘Square::Square()’ Board.cpp:7: note: candidates are: Square::Square(int) Board.hh:4: note: Square::Square(const Square&) Board.cpp:24: error: variable-sized object ‘board’ may not be initialized Board.cpp:24: error: no matching function for call to ‘Square::Square()’ Board.cpp:7: note: candidates are: Square::Square(int) Board.hh:4: note: Square::Square(const Square&)
Any tips?
--Dave