4

我正在解码 bencode,并且有一些适用于 gcc 4.4 的代码。但是最近升级到 gcc 4.6 这个代码不再构建:

#ifndef BENCODE_VALUETYPES_H
#define BENCODE_VALUETYPES_H

#include <boost/variant.hpp>

#include <string>
#include <vector>
#include <map>

namespace bencode {

  typedef boost::make_recursive_variant<
    int,
    std::string,
    std::vector<boost::recursive_variant_>,
    std::map<std::string, boost::recursive_variant_> >::type Value;

  typedef std::map<std::string, Value> ValueDictionary;
  typedef std::vector<Value> ValueVector;

};

#endif

g++ 给出了这个错误信息:

/usr/include/c++/4.6/bits/stl_pair.h: In instantiation of 'std::pair<const std::basic_string<char>, boost::recursive_variant_>':
Decoder.cpp:97:39:   instantiated from here
/usr/include/c++/4.6/bits/stl_pair.h:93:11: error: 'std::pair<_T1, _T2>::second' has incomplete type
/usr/include/boost/variant/variant_fwd.hpp:232:12: error: forward declaration of 'struct boost::recursive_variant_'

最新的 boost 版本(目前为 1.48)的文档指出“由于几个编译器中的标准一致性问题,make_recursive_variant 不被普遍支持”,您应该使用 recursive_wrapper。但是我在进行更改时遇到了问题:有人知道使用包装器应该是什么样子吗?

4

1 回答 1

4

在包含 boost 变体头文件之前,尝试在头文件中定义以下内容。

#define BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT
#include <boost/variant.hpp>

我遇到了同样的问题,并在boost variant recursive找到了解决方案

于 2012-04-08T02:47:01.773 回答