0

我编写了一个代码来gz使用boost.

class foo() {
  std::ofstream traceOut;
  struct traceRec {
    traceRec(uint64_t c) : cycle(c) {};
    uint64_t cycle;
  };
  void writeTrace(traceRec &rec)
  {
    try {
      boost::iostreams::filtering_istream in;
      in.push(boost::iostreams::gzip_decompressor());
      in.push(traceOut);   // ERROR
      std::cout << rec.cycle << std::endl;
    }
    catch(const boost::iostreams::gzip_error& e) {
      std::cout << e.what() << '\n';
    }
  }
  void init() {
    traceOut.open("log.gz", std::ios_base::in | std::ios_base::binary);
  }
  void bar() {
    traceRec rec (1000);
    writeTrace(rec);
  }
};

但是我在编译时收到此错误

/opt/boost_1_33_1/boost/iostreams/chain.hpp: In member function ‘void boost::iostreams::detail::chain_client<Chain>::push(std::basic_ostream<_CharT2,      _Traits2>&, int, int) [with CharType = char, TraitsType = std::char_traits<char>, Chain = boost::iostreams::chain<boost::iostreams::input, char, 
std::char_traits<char>, std::allocator<char> >]’:
test.cpp:   instantiated from here
/opt/boost_1_33_1/boost/iostreams/chain.hpp:472: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’ 
/opt/boost_1_33_1/boost/iostreams/traits.hpp: At global scope:
/opt/boost_1_33_1/boost/iostreams/traits.hpp: In instantiation of ‘boost::iostreams::detail::member_category<mpl_::void_>’:
/opt/boost_1_33_1/boost/mpl/eval_if.hpp:38:   instantiated from ‘boost::mpl::eval_if<boost::iostreams::is_std_io<mpl_::void_>, boost::iostreams::select<boost::iostreams::is_iostream<mpl_::void_>, boost::iostreams::iostream_tag, boost::iostreams::is_istream<mpl_::void_>, boost::iostreams::istream_tag, boost::iostreams::is_ostream<mpl_::void_>, boost::iostreams::ostream_tag, boost::iostreams::is_streambuf<mpl_::void_>, boost::iostreams::streambuf_tag, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_>, boost::iostreams::detail::member_category<mpl_::void_> >’
....

这意味着什么?

4

1 回答 1

2

请看这个,push() 方法必须接收流而不是任意对象

EDIT1(以下评论交流)

更改类型traceOutstd::ifstream解决构建问题(至少使用 boost 1.52)

于 2013-03-13T19:36:44.583 回答