Archived

This topic is now archived and is closed to further replies.

JaZsT

data to a class and back....??

Recommended Posts

Hello !! I have got some global twodimensional arrays of ints (int MapArray[100][100]....). I want those global arrays to be accessible to Unit classes(so that a unit can read from and write to those arrays). How do I do that whithout copying the whole array to unit, and back??? The problem is that I don''t know how to use pointers with twodimensional arrays.... Please help ! Thanx a lot!! -- Uros Life lived unexplored is life not worth living !

Share this post


Link to post
Share on other sites
If your array is global, you shouldn''t need another pointer to it. I think if you declare it using extern int MapArray[100][100]; in every file that needs to use it, it should work.

Share this post


Link to post
Share on other sites
I supose you''re using C++, aren''t you? You should be able to acces your array from any method (or class member function) without further ado:

int MapArray[100][100];
class unit {...};

int unit::read_map(int x, int y) {
return MapArray[x][y];
}

No need for pointers as far as I can see.
The only problem you might encounter is that if you define your methods (s.a.) in another file you will have to write something like this:

extern int MapArray[100][100];

into it (just in case you aren''t familiar with C++ variable scopes).

------------------------------------------------------------
"To a computer, chaos is just another kind of order."

Share this post


Link to post
Share on other sites