6

Using g++ version 4.7.2, if I try compiling the following

#include <boost/date_time/local_time/local_time.hpp> 

class Bar
{
public:

Bar() { tz_db_.load_from_file("/home/date_time_zonespec.csv"); }

private:
    boost::local_time::tz_database tz_db_;
};

int main()
{
    return 0;
}

with -std=c++0x I get the following error.

In file included from /usr/local/include/boost/date_time/local_time/local_time_types.hpp:18:0,
                 from /usr/local/include/boost/date_time/local_time/local_time.hpp:13,
                 from test.h:4,
                 from test.cpp:1: /usr/local/include/boost/date_time/local_time/custom_time_zone.hpp: In instantiation of ‘bool boost::local_time::custom_time_zone_base<CharT>::has_dst() const [with CharT = char]’: test.cpp:11:1:   required from here /usr/local/include/boost/date_time/local_time/custom_time_zone.hpp:67:30: error: cannot convert ‘const boost::shared_ptr<boost::date_time::dst_day_calc_rule<boost::gregorian::date>
>’ to ‘bool’ in return

If I leave off the c++0x option, everything is fine. Can anybody tell me what's going on here?

4

1 回答 1

12

当您为 C++11 构建时,boost::shared_ptr::operator bool()声明为explicit. 这通常是一件好事,但不幸的是它破坏了依赖隐式转换的代码,例如这个函数(这是你的错误的原因):

virtual bool has_dst() const
{
  return (dst_calc_rules_); //if calc_rule is set the tz has dst
}

哪里dst_calc_rules_shared_ptr

在 Boost 的某个人开始修复它之前,您可以做两件事:

  • 破解该功能return bool(dst_calc_rules_);
  • 定义BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS为允许隐式转换。
于 2013-03-05T21:45:22.023 回答