Sign in to follow this  

Assigning new values to existing int arrays

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

Hi! Lets say i have 2 arrays... int g_GameBoard[225]; int g_GameBoard1[225]; Both of these arrays have been initialized and contain information(a number) in each 225 of the elements, How does a person assign the values in the second array(g_GameBoard1) to the first array(g_GameBoard); g_GameBoard[] = g_GameBoard1[]; I know this is wrong but whats proper syntax or way of doing it? Hope this isnt too confusing?! lol. Thanks alot!

Share this post


Link to post
Share on other sites
const int size = 225;
int g_GameBoard[size];
int g_GameBoard1[size];

std::copy(g_GameBoard1, g_GameBoard1 + size, g_GameBoard);


Using either std::vector or boost::array would provide an opportunity to simply write g_GameBoard = g_GameBoard1;. Also, you should consider factoring repeated information (such as having your game boards represented as arrays) by creating a class to represent a game board. The default assignment operator of a class containing an array will also assign that array.

Share this post


Link to post
Share on other sites

This topic is 3629 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this