passing an array to a header

I have been reading about headers but i am not understanding it when it comes to arrays. Of course i am doing it wrong but what is the best way or am i just messing something. row and column undeclared identifier how do i properly pass an array to a header file
in my main.cpp i have it initialed like this:
const int row = 3;
const int column = 3;
char position[row][column];

a sample input when accessing the class is
TTT play;
play.display(position)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// header file     row and column undeclared identifier
#include <iostream>
using namespace std;

#ifndef GAME_H
#define GAME_H

class TTT{
public:
	void display(char position[row][column]);
};

#endif


//cpp for header
#include "Game.h"
#include <iostream>

using namespace std;

void TTT::display(char position[row][column])
{
	cout << "     |     |     " << endl;
	cout << "  " << position[1][1] << "  |  " << position[1][2] << "  |  " << position[1][3] << endl;

	cout << "_____|_____|_____" << endl;
	cout << "     |     |     " << endl;

	cout << "  " << position[2][1] << "  |  " << position[2][2] << "  |  " << position[2][3] << endl;

	cout << "_____|_____|_____" << endl;
	cout << "     |     |     " << endl;

	cout << "  " << position[3][1] << "  |  " << position[3][2] << "  |  " << position[3][3] << endl;

	cout << "     |     |     " << endl << endl;
};


thank you for your time
Remember that array indexes start at ZERO, not at 1.

So accessing position[3][3] in your function is out of bounds if the array is only of size [3][3].

Apart from that I don't see anything wrong with the code (although the class is kind of meaningless.... your 'display' behaves more like a global function).


EDIT:

Actually... lack of 'row' and 'column' being defined might be a problem. You might have to move those definitions to the header file.
Last edited on
thank you i got it now i have a new problem gonna work on it before i post another question. I was using the array positions at [0] for something else but i changed so i don't confuse myself later on
Topic archived. No new replies allowed.