check out this error...

I am trying to pass a 2D array of char to a function in my class.

this is the class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  class World
{
private:
	char world_array[COLUMNS][ROWS];

	bool out_of_bounds( int col, int row, bool verbose = false );

public:
	World();

	void display( bool side_marks = false );
	void create_life( int col, int row );
	void kill_life( int col, int row );
  //add additional functions here:
	void generation( char world_array[COLUMNS][ROWS] );
};


i then have this in my main
1
2
char world_array[COLUMNS][ROWS];
myWorld.generation( world_array[COLUMNS][ROWS] );


my error reads " argument of type char is incompatible with parameter of type "char(*)[22] "

i do not understand if in my code my function looks like this:

void generation( char world_array[COLUMNS][ROWS] );

how come when i scroll over that same line over "generation" i see it show up
like this:

void World::generation(char (*world_array)[22] )

why does the parameter look so different? its a pointer correct? how can i correct this in order to use my function properly?
Maybe it is trying to use the private variable not sure why you have it anyways doesn't even look like you are using the private char array
myWorld.generation( world_array[COLUMNS][ROWS]);
This is not passing the whole array. This is passing the value at location world_array offset by COLUMNS and ROWS. In other words, you are passing one value (and that value is not within the array). That is why the compiler complains about the types not matching. You passed a char to a char pointer.
Try:
 
myWorld.generation(world_array);
Last edited on
thanks a ton i totally understand why now.
Topic archived. No new replies allowed.