test.cpp

来自「使用tasking for mc683XX C编译器」· C++ 代码 · 共 46 行

CPP
46
字号
//test.cpp
//	test the CDate class

#include <stdio.h>
#include "cdate.h"


void main(void)
{
int days;
CDate tomorrow,	temp,		  	//default constructor
	  today(25, CDate::September, 1997);	//initialization constructor
CDate birthday  = today;	  	//copy constructor
CDate* datePtr;

   tomorrow = today;			//assignment 
   temp		= tomorrow++;		//post increment
   temp		= ++birthday;		//pre increment

   if(birthday == tomorrow) {	//eqality operator
//   	printf("start last minute party plans!\n");
     birthday.show();			//display the date
   	 }

   birthday.Set(12, CDate::January, 1976);
   	
   datePtr = new CDate(31, CDate::December, 1997);

//with compiler optimizations ON the automatic variable 'days'
//will be removed because it is not used after being assigned.
//try disabling 'compiler optimizations that interfere with debugging,'
//in menu EDE : C/C++ Compiler Options : Project Options : Optimization
//and compare the resulting assembly language.
   days = datePtr->DayOfYear();

   datePtr->show();

   (*datePtr)++;				//increment to new year
   
   delete datePtr;			//kill datePtr
   
   datePtr->Set(1, CDate::October, 1997);	//should trap, datePtr is dead	 

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?