【发布时间】:2018-08-22 07:49:32
【问题描述】:
这里unsigned long EVTime::seconds() 方法与ptime p(d,seconds(s)); 冲突。如果我将 ptime seconds(s) 更改为分钟/小时,那么它工作正常。
如果我将seconds(s) 更改为minutes(s) 或hours(s),那么只有它会起作用。我是 C++ 新手,请任何人帮助解决这个冲突。
evt.cpp:
unsigned long EVTime::seconds()
{
ptime t(date(1901,Jan,1),time_duration(0,0,0));
time_duration td = utcdatetime - t;
return (unsigned long)td.total_seconds();
}
EVTime::EVTime(unsigned long s)
{
date d(1901,1,1);
ptime p(d,seconds(s));
utcdatetime=p;
}
evt.h:
class EVTime
{
public:
EVTime(unsigned long s);
unsigned long seconds();
ptime utcdatetime;
};
main.cpp:
int main()
{
EVTime t(222l);
cout<<"seconds since 1901: "<<t.seconds()<<endl;
}
错误代码:
evtime.cpp: In constructor ‘EVTime::EVTime(long unsigned int)’:
evtime.cpp:35: error: no matching function for call to ‘EVTime::seconds(long
unsigned int&)’
evtime.cpp:14: note: candidates are: long unsigned int EVTime::seconds()
【问题讨论】:
-
看起来你的函数
seconds()没有参数,但是当你调用它时你发送它s:ptime p(d,seconds(s));(我认为*s 是为了强调?) -
请去掉强调的星号,它们会破坏代码并且对讨论没有任何贡献。如果您想强调代码中的某些内容,只需使用注释即可。无论如何,我认为你的问题是你依赖
using namespace。这是个错误。如果需要使用boost::posix_time::seconds,每次都拼写boost::posix_time::seconds,或者使用命名空间别名。 -
谢谢,“boost::posix_time::seconds”这条线对我有用