![]() |
| ||
| Dynamic arrays in a class I'm working on a program that has a class Board, and two inherited classes that will implement different games, but I'm having problems with setting up the initial Board class. The problem is that I don't know how to make it so the board array in the protected section of the Board.h file takes on the values input in a and b in the main.cpp file. Here's my main.cpp #include <iostream>my Board.cpp #include "Board.h"and my Board.h file #ifndef BOARD_H_INCLUDED |
| ||
| Re: Dynamic arrays in a class Instead of: int board[4][4]; Replace with: int** board; Now we can dynamically allocate space for the 2D board array. In set_board(), we need to do the dynamic allocation like so: // First allocate for the first dimension |
| All times are GMT -4. The time now is 5:57 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC