Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#ActualAndy Gainey

Posted 28 July 2014 - 08:55 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:
Class::Class()
{
  std::fill(array, array + 2, false);
}
 
At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.

#4Andy Gainey

Posted 28 July 2014 - 08:54 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:

Class::Class()
{
  std::fill(array, array + 2, false);
}

At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.


#3Andy Gainey

Posted 28 July 2014 - 08:53 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:

Class::Class()
{
  std::fill(array, array + 2, false);
}

At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.


#2Andy Gainey

Posted 28 July 2014 - 08:53 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:

Class::Class()
{
  std::fill(array, array + 2, false);
}

At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.


#1Andy Gainey

Posted 28 July 2014 - 08:53 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:

Class::Class()
{
  std::fill(array, array + 2, false);
}

At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.


PARTNERS