Jump to content
  • Advertisement


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

easy class help please

This topic is 6514 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

I have a global class array like: class world { int x; int y; }; world rooms[10][10]; what I wanted to know is why cant I initialize the values of each object unless I''m in a function? If I do it in a function it will only be changed in that function and no where else right? The way I''ve been doing it is in my main function which is a pain. can someone help me out? If I do it outside of main I get a ton of errors. pppppllllleeeeaaassssseee help!!!

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
What you need is a class constructor. Redefine you class as:

class world
int x, y;

world( void ) { x = y = 0; }
world(int tx, int ty) { x = tx; y = ty; }

world rooms[][10] = {
{ world(0, 0), world(0, 1), ... world(0, 9) },
{ world(1, 0), world(1, 1), ... world(1, 9) },
{ world(9, 0), world(9, 1), ... world(9, 9) }

Also, don''t forget the public: bit otherwise you won''t be able to access the x and y variables.


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!