Jump to content
  • Advertisement

Archived

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

JaZsT

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

This topic is 6067 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Seems cnirrad was quicker than I was :-)

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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!