C ++构造函数,析构函数,类型转换错误

时间:2013-03-14 03:32:46

标签: c++ constructor type-conversion destructor

嘿伙计们我正在尝试为模块创建一个实现文件。它有我创建的头文件和.CC文件。在我的.CC文件中,我最初有一个main函数,但由于这是一个类的赋值,它要求在实现中没有main函数。

  9 #include <curses.h>
 10 #include <sys/time.h>
 11 #include <time.h>
 12 #include "fmttime.h"
 13
 14
 15 struct ExpandedTime
 16 {
 17
 18     int et_usec;
 19     int et_sec;
 20     int et_min;
 21     int et_hour;
 22
 23 };
 24 ExpandedTime* localTime(struct timeval* tv, ExpandedTime* etime);
 25
 26
 27 struct timeval tv;
 28 struct ExpandedTime etime;
 29 gettimeofday(&tv, NULL);
 30 localTime(&tv,&etime);
 31
 32
 33
 34 ExpandedTime* localTime(struct timeval* tv, ExpandedTime* etime)
 35 {
 36     tzset();                                    // Corrects timezone
 37
 38     int epochT = (tv->tv_sec) - timezone;       // Epoch seconds with
 39     int epochUT = tv->tv_usec;                  // Timezone correction
 40
 41     int seconds = epochT % 60;
 42     epochT /= 60;
 43     etime->et_sec = seconds;
 44     etime->et_usec = epochUT;
 45
 46     int minutes = epochT % 60;
 47     epochT /= 60;
 48     etime->et_min = minutes;
 49
 50     int hours = (epochT % 24) + daylight;       // Hours with DST correction

抱歉,最后几行被切断了,复制并粘贴Mhedit在腻子糟透了。无论如何第29和30行给我一个构造函数,析构函数或类型转换错误,我无法弄清楚为什么。当我有一个主要功能封闭这些陈述时,一切都很好,花花公子...但当我删除主要...它只是崩溃了。非常感谢任何帮助。谢谢。

1 个答案:

答案 0 :(得分:1)

27 struct timeval tv;
28 struct ExpandedTime etime;
29 gettimeofday(&tv, NULL);
30 localTime(&tv,&etime);

此代码不在任何函数内。它赤裸裸地坐在全球范围的荒野中。它需要显示回家,返回功能,任何功能。那里有狼。