Jump to content
  • Advertisement
Sign in to follow this  
_damN_

Assigning new values to existing int arrays

This topic is 3822 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
Advertisement
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
Sign in to follow this  

  • 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!