Thread: C++ Arrays
View Single Post
Old 11-09-2006, 03:12 PM   #15 (permalink)
Sep102
Forum Expert
 
Join Date: Aug 2004
Location: Redmond, WA
Age: 21
Posts: 1,288
Send a message via AIM to Sep102 Send a message via MSN to Sep102
Default

Pretty much, I can give you a "possibly" more appealing way that uses std::copy from the algorithm header, but that's about it.

Code:
#include <algorithm>

/*...*/

Calendar()
{
	Month table[] =
	{
		Month("January", 31),
		Month("February", 28),
		Month("March", 31),
		Month("April", 30),
		Month("May", 31),
		Month("June", 30),
		Month("July", 31),
		Month("August", 31),
		Month("September", 30),
		Month("October", 31),
		Month("November", 30),
		Month("December", 31)
	};
	
	months = new Month[12];

	std::copy(&table[0], &table[12], months);
}
std::copy copies from the iterator (pointer in this case) &table[0], or the first element of table, to one before the second argument of the function (&table[12]) or the last element of table. It copies this into the third argument, months.

Last edited by Sep102; 11-09-2006 at 03:18 PM.
Sep102 is offline   Reply With Quote