很郁闷的问题,很幼稚的问题
问题越幼稚越郁闷。
在MFC中添加了一个类:time
然后在当前项目中的其他cpp文件中要用该类,是这么用的:time t;
结果编译报错:缺少;(在标示符t的前面)
如果注释掉time t;程序是可以正常编译运行的。
这样用能错么?
顺便附上time的代码吧
#pragma once
class time
{
public:
time();
int compare(time &t1,time &t2);
int compare_time(CTime &t1,CTime &t2);
int compare_date(CTime &t1,CTime &t2);
private:
int hour;
int minite;
int second;
};
#include "StdAfx.h"
#include "time.h"
time::time(){
hour=0;
minite=0;
second=0;
}
int time::compare(time &t1,time &t2){
if(t1.hour>t2.hour)return 1;
if(t1.hour<t2.hour)return -1;
if(t1.minite>t2.minite)return 1;
if(t1.minite<t2.minite)return -1;
if(t1.second>t2.second)return 1;
if(t1.second<t2.second)return -1;
return 0;
}
int time::compare_time(CTime &t1,CTime &t2){
if(t1.GetHour()>t2.GetHour())return 1;
if(t1.GetHour()<t2.GetHour())return -1;
if(t1.GetMinute()>t2.GetMinute())return 1;
if(t1.GetMinute()<t2.GetMinute())return -1;
if(t1.GetSecond()>t2.GetSecond())return 1;
if(t1.GetSecond()<t2.GetSecond())return -1;
return 0;
}
int time::compare_date(CTime &t1,CTime &t2){
if(t1.GetYear()>t2.GetYear())return 1;
if(t1.GetYear()<t2.GetYear())return -1;
if(t1.GetMonth()>t2.GetMonth())return 1;
if(t1.GetMonth()<t2.GetMonth())return -1;
if(t1.GetDay()>t2.GetDay())return 1;
if(t1.GetDay()<t2.GetDay())return -1;
return 0;
}