I have used some info from a previous thread. I still can't get it to work, I want to make a 5 by 5 dynamically allocated array. The reason it is dynamic, because in the finished program the dimensions will e specified by the user. Anyhow here is the code:
Code:
#ifndef _GRIDWORLD_H
#define _GRIDWORLD_H
#include "DLList.h"
#include "personarray.h"
class CGridworld
{
public:
CGridworld(int nrows=5, int ncols=5);//constructor with gridsize
//~CGridworld();
void move(int pid, int new_row, int new_col); //move person pid to
// (new_row,new_col)
void printMembers(int i, int j); //print the people in district (i, j)
private:
int **Grid; //two-dimentional array
int nrows; //number of rows in this grid world
int ncols; //number of columns in this grid world
//CPersonArray P; //stores person info
};
#endif
//============GRIDWORLD.CPP
#include <iostream>
using namespace std;
#include "gridworld.h"
CGridworld::CGridworld( int nrows, int ncols)
{
Grid = new int *[nrows];
for( int i = 1; i < nrows; i++){
Grid[i] = new int[ncols];
}
for(int j = 1; j < nrows; j++){
Grid[j] = 0; //initializing the whole grid to zero
cout << Grid[j] << endl;
}
}
right now the code gives me 8 cols and 5 rows
any ideas,
axon