I'm trying to iterate through a dynamically allocated 2d array of characters and initialize all of the spaces to a blank. When I attempt to do this in the constructor, I get the error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive] from *showMap[i][j] = ' '; and I'm not exactly sure how to fix this. Additionally, I know I'm supposed to allocate memory for pointers and such when I declare them but I've never done it for a 2d array before, and I was wondering if I'm using the 'new' keyword correctly in this case or if I'm allocating memory correctly at all? Each element in the array is supposed to store 1 character.
I was also wondering if someone could look over my print statement? It should basically just print all the elements to the screen in this sort of style:
1 2 3 4
|H |
| T |
| |
| C|
Most elements will be blank, but it should sort of be presented in a 10x30 square with |'s fenced on both sides. The characters that ARE filled in represent runners in a marathon, and the runner who gets to the bottom right corner first wins.
I appreciate any help!! As a side note, I was wondering if someone could explain if I did my destructor correctly? I searched online for how to destruct a dynamic 2D array of characters and ended up with what's below, but I don't understand why I iterate and delete through MAX_ROWS only and not MAX_COLS as well.
#ifndef VIEW_H
#define VIEW_H
#define MAX_ROWS 10
#define MAX_COLS 30
//#include <iostream> // <--- If you include this header at the right time these are not need, but OK if you feel they are needed. Otherwise they are not needed in this file.
//#include <string>
//#include "Position.h" // <--- You did not provide this header file.
//using namespace std; // <--- This is bad enough, but NEVER put in a header file.
// http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/class View
{
public:
View();
~View();
void print();
private:
char** showMap[MAX_ROWS][MAX_COLS]; // <--- Is this a pointer to a pointer or a char array? One or the other, but not both.
};
#endif
If the comments do not explain something let me know.