嘿伙计们,我正在尝试为模块创建一个实现文件。它有一个我创建的头文件和一个 .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
抱歉,最后几行被截断了,在腻子中复制和粘贴 Mcedit 很糟糕。无论如何,第 29 行和第 30 行给了我一个构造函数、析构函数或类型转换错误,我不知道为什么。当我有一个包含这些语句的 main 函数时,一切都很好而且很花哨……但是当我删除 Main 时……它就崩溃了。任何帮助将不胜感激,谢谢。