Thread: C++ Arrays
View Single Post
Old 11-09-2006, 03:52 PM   #17 (permalink)
noobie
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

thats not a good example, you are wasting memory..

I would use something like this:

Code:
class Calendar{
	public:
		Month * table;
		Calendar()
		{
			table =new Month[12]; //have a default const for Month
			//initialize your private values
	
			table[0]=Month("January", 31);
			table[1]=Month("February", 28);
			table[2]=Month("March", 31);
			table[3]=Month("April", 30);
			table[4]=Month("May", 31);
			table[5]=Month("June", 30);
			table[6]=Month("July", 31);
			table[7]=Month("August", 31);
			table[8]=Month("September", 30);
			table[9]=Month("October", 31);
			table[10]=Month("November", 30);
			table[11]=Month("December", 31);
		}
		~Calendar()
		{
			delete [] table;
		}

};
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

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