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

C++ constructor, destructor, type conversion error

本文关键字:错误 类型转换 析构函数 c++ 构造函数      更新时间:2023-10-16

嘿,伙计们,我正试图创建一个模块的实现文件。它有我创建的头文件和一个。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

对不起,最后几行被剪掉了,在putty中复制粘贴Mcedit很糟糕。无论如何,第29行和30行给了我一个构造函数,析构函数或类型转换错误,我不知道为什么。当我有一个包含这些语句的main函数时,一切都很好。但当我移除了主…它就这么坏了。如有任何帮助,不胜感激。

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

此代码不在任何函数内部。它赤裸地坐在全球范围的荒野中。它需要在函数中显示出来,任何函数都可以。外面有狼。