无法将'const timeval'转换为'__time_t {aka long int}'

时间:2017-07-04 22:46:57

标签: linux compilation makefile time c++

我正在尝试编译https://sourceforge.net/p/dom-s-orm/code/HEAD/tree/trunk/src/

每当我尝试编译它时,我都会收到此错误:

[root@localhost dev]# gmake all
(cd objects; gmake)
gmake[1]: Entering directory '/home/burst/dev/objects'
--> Compiling object helper Account from ../output/objects/Account_.cxx
In file included from ../output/objects/Account_.hxx:11:0,
                 from ../output/objects/Account_.cxx:4:
../build/contrib/DORM/include/Timestamp.hpp: In constructor ‘DORM::Timestamp::Timestamp(const timeval&)’:
../build/contrib/DORM/include/Timestamp.hpp:19:44: error: cannot convert ‘const timeval’ to ‘__time_t {aka long int}’ in initialization
    Timestamp(const struct timeval &t): tv{t} {};
                                            ^
gmake[1]: *** [../build/gmake/objects.gmk:59: ../output/objects/Account_.o] Error 1
gmake[1]: Leaving directory '/home/burst/dev/objects'
gmake: *** [Makefile:5: all] Error 2

Timestamp.hpp的内容是:

#ifndef DORM__INCLUDE__TIMESTAMP_HPP
#define DORM__INCLUDE__TIMESTAMP_HPP

#include <cppconn/sqlstring.h>

#include <string>
#include <ctime>
#include <sys/time.h>


namespace DORM {

    class Timestamp {
        public:
            struct timeval tv;

            Timestamp(): tv{0, 0} {};
            Timestamp(const time_t &t): tv{t, 0} {};
            Timestamp(const struct timeval &t): tv{t} {};

            Timestamp(const std::string time_str);
            Timestamp(sql::SQLString time_str);

            operator time_t() { return tv.tv_sec; };
            operator timeval() { return tv; };
    };

}

#endif

欢迎任何帮助以解决此问题。

非常感谢!

此致

1 个答案:

答案 0 :(得分:0)

由于struct timeval是一个简单的C结构,因此它没有复制构造函数。这会使tv{t}进入

Timestamp(const struct timeval &t): tv{t} {};

汇总initialization(请参阅语法2),尝试使用tv.sec初始化ttv.sectime_t而不是struct timeval,因此错误。

请使用括号,如下所示:

Timestamp(const struct timeval &t): tv(t) {};