无法将“const timeval”转换为“__time_t aka long int”
Posted
技术标签:
【中文标题】无法将“const timeval”转换为“__time_t aka long int”【英文标题】:cannot convert ‘const timeval’ to ‘__time_t aka long int’无法将“const timeval”转换为“__time_t aka long int” 【发布时间】:2017-07-04 22:46:56 【问题描述】:我正在尝试编译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): tvt ;
^
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(): tv0, 0 ;
Timestamp(const time_t &t): tvt, 0 ;
Timestamp(const struct timeval &t): tvt ;
Timestamp(const std::string time_str);
Timestamp(sql::SQLString time_str);
operator time_t() return tv.tv_sec; ;
operator timeval() return tv; ;
;
#endif
欢迎任何帮助以解决此问题。
非常感谢!
问候
【问题讨论】:
【参考方案1】:由于struct timeval
是一个简单的C 结构,它没有复制构造函数。这使得tvt
在
Timestamp(const struct timeval &t): tvt ;
聚合 initialization(参见语法 2),尝试使用 t
初始化 tv.sec
。 tv.sec
是 time_t
而不是 struct timeval
,因此会出现错误。
像这样使用括号:
Timestamp(const struct timeval &t): tv(t) ;
【讨论】:
以上是关于无法将“const timeval”转换为“__time_t aka long int”的主要内容,如果未能解决你的问题,请参考以下文章
宏字符串:#define __T(x) x 是啥意思?和 __T(#x)?