我不明白为什么这个代码使用g ++ 4.7.2扼流圈:两个time_point实例之间的差异不是持续时间?
#include <chrono>
main()
{
std::chrono::system_clock::time_point t1, t2 ;
std::chrono::seconds delay ;
t1 = std::chrono::system_clock::time_point::max() ;
t2 = std::chrono::system_clock::now() ;
delay = t1 - t2 ;
// t1 = t2 + delay ;
// t1 = t2 - delay ;
}
与错误:
test.cc: In function ‘int main()’:
test.cc:10:18: error: no match for ‘operator=’ in ‘delay = std::chrono::operator,<std::chrono::system_clock, std::chrono::duration<long int, std::ratio<1l, 1000000l> >, std::chrono::duration<long int, std::ratio<1l, 1000000l> > >((*(const std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<long int, std::ratio<1l, 1000000l> > >*)(& t1)), (*(const std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<long int, std::ratio<1l, 1000000l> > >*)(& t2)))’
这在我看来, “time_point - time_point” 提供了一个 “持续时间” 。
噢,是的,对,C++编译器**仍**吸吮错误信息。 – 2013-04-25 17:45:17
@KonradRudolph库作者可以使用更自由的'static_assert'用法大大改善它们,我不知道他们为什么不这样做。 – 2013-04-25 17:49:57
@DavidBrown:您不能使用'static_assert'来报告是否存在合适的函数/运算符过载。概念可能有所帮助,但它们还不存在。 – 2013-04-25 17:54:34