boost::date_time::days_until_weekday 的编译错误
compile error for boost::date_time::days_until_weekday
我目前正在研究 boost::date_time
。在这样做的同时,我发现了 days_until_weekday
(documentation link) 函数,它对我来说非常有用。不幸的是,我从以下代码片段中得到编译时错误
date f(date d){
return next_weekday(d, boost::date_time::weekdays::Friday);
}
阅读
> In file included from
> /usr/include/boost/date_time/gregorian/gregorian_types.hpp:25:0,
> from /usr/include/boost/date_time/posix_time/posix_time_config.hpp:18,
> from /usr/include/boost/date_time/posix_time/posix_time_system.hpp:13,
> from /usr/include/boost/date_time/posix_time/ptime.hpp:12,
> from /usr/include/boost/date_time/posix_time/posix_time.hpp:15,
> from prog.cpp:3: /usr/include/boost/date_time/date_generators.hpp: In instantiation of
> 'typename date_type::duration_type
> boost::date_time::days_until_weekday(const date_type&, const
> weekday_type&) [with date_type = boost::gregorian::date; weekday_type
> = boost::date_time::weekdays; typename date_type::duration_type = boost::gregorian::date_duration]':
> /usr/include/boost/date_time/date_generators.hpp:488:34: required
> from 'date_type boost::date_time::next_weekday(const date_type&, const
> weekday_type&) [with date_type = boost::gregorian::date; weekday_type
> = boost::date_time::weekdays]' prog.cpp:11:67: required from here /usr/include/boost/date_time/date_generators.hpp:452:37: error:
> request for member 'as_number' in 'wd', which is of non-class type
> 'const boost::date_time::weekdays'
> duration_type dd(wd.as_number() - d.day_of_week().as_number());
转到 here 粘贴我的代码。
由于导致错误的代码段太短,我真的没有办法解决这个问题。
顺便说一下,我正在使用 clang 3.7.0 升级 1.60.0。
您需要将 date_time 枚举转换为与传递给函数的 weekday_type 预期接口相匹配的对象。使用 greg_weekday 函数为您完成此操作,例如:
return next_weekday(d, boost::gregorian::greg_weekday(boost::date_time::Friday));
在 VS2015 和 boost 1.53 下为我编译。
A link 此函数的文档:
greg_weekday
我目前正在研究 boost::date_time
。在这样做的同时,我发现了 days_until_weekday
(documentation link) 函数,它对我来说非常有用。不幸的是,我从以下代码片段中得到编译时错误
date f(date d){
return next_weekday(d, boost::date_time::weekdays::Friday);
}
阅读
> In file included from
> /usr/include/boost/date_time/gregorian/gregorian_types.hpp:25:0,
> from /usr/include/boost/date_time/posix_time/posix_time_config.hpp:18,
> from /usr/include/boost/date_time/posix_time/posix_time_system.hpp:13,
> from /usr/include/boost/date_time/posix_time/ptime.hpp:12,
> from /usr/include/boost/date_time/posix_time/posix_time.hpp:15,
> from prog.cpp:3: /usr/include/boost/date_time/date_generators.hpp: In instantiation of
> 'typename date_type::duration_type
> boost::date_time::days_until_weekday(const date_type&, const
> weekday_type&) [with date_type = boost::gregorian::date; weekday_type
> = boost::date_time::weekdays; typename date_type::duration_type = boost::gregorian::date_duration]':
> /usr/include/boost/date_time/date_generators.hpp:488:34: required
> from 'date_type boost::date_time::next_weekday(const date_type&, const
> weekday_type&) [with date_type = boost::gregorian::date; weekday_type
> = boost::date_time::weekdays]' prog.cpp:11:67: required from here /usr/include/boost/date_time/date_generators.hpp:452:37: error:
> request for member 'as_number' in 'wd', which is of non-class type
> 'const boost::date_time::weekdays'
> duration_type dd(wd.as_number() - d.day_of_week().as_number());
转到 here 粘贴我的代码。
由于导致错误的代码段太短,我真的没有办法解决这个问题。
顺便说一下,我正在使用 clang 3.7.0 升级 1.60.0。
您需要将 date_time 枚举转换为与传递给函数的 weekday_type 预期接口相匹配的对象。使用 greg_weekday 函数为您完成此操作,例如:
return next_weekday(d, boost::gregorian::greg_weekday(boost::date_time::Friday));
在 VS2015 和 boost 1.53 下为我编译。
A link 此函数的文档: greg_weekday