#includeiostreamusingnamespacestd;classDate{private://私有数据成员intYear,Month,Date;public://外部接口,公有成员函数Date(intY,intM,intD){Year=Y;Month=M;Date=D;}voidSetDate(intNewY,intNewM,intNewD);//成员函数,类体外声明“年月日输入”voidShowTime()//成员函数,类体内声明“年月日输出”{coutYear\"年\"Month\"月\"Date\"日\"endl;}};voidDate::SetDate(intNewY,intNewM,intNewD){//cinYearMonthDate;Year=NewY;Month=NewM;Date=NewD;}intmain(){inty=0,m=0,d=0;cout\"本程序完成日期输入输出任务:\"endl;cout\"日期输入:\";cinymd;Datea;a.SetDate(y,m,d);a.ShowTime();return0;}1e:\\c\\date\\date\\main.cpp(6):errorC2461:“Date”:构造函数语法缺少形参1e:\\c\\date\\date\\main.cpp(10):errorC2513:“Date”:在“=”前没有声明变量1e:\\c\\date\\date\\main.cpp(14):errorC2275:“Date”:将此类型用作表达式非法1e:\\c\\date\\date\\main.cpp(23):errorC2513:“Date”:在“=”前没有声明变量1e:\\c\\date\\date\\main.cpp(32):errorC2512:“Date”:没有合适的默认构造函数可用
|