VC6上boost 1.34.1的boost类中出现错误C2039

Error C2039 in boost class with Boost 1.34.1 on VC6

本文关键字:boost 错误 C2039 VC6      更新时间:2023-10-16

一些历史:我最初想为ASIO使用boost,但后来发现ASIO无法与VC++6.0一起工作(这是一个要求)。在合并boost时,我发现了Multi_Index_Container和Signals的用途。在发现ASIO不兼容后,我将boost降级到1.34.1版本,以便它支持VC6。现在我正试图消除所有其他的编译错误。

起初,我有这样的代码和错误:我正在尝试使用版本1.34.1中的Boost Multi_Index来设置结构的集合。此多索引容器将具有2个唯一密钥(ID和Name),因为我必须能够用任意一个键进行搜索。我对VC++6.0 SP5:进行了编译器特定的更正

boost::multi_index::multi_index_container
member_offset<A,int,offsetof(A,x)>

我的完整声明是:

enum RESPONSE_CODES
{
    Pass = 200,
    Fail = 201,
    Hex = 202,
    Decimal = 203,
    String = 204,
    Help = 205,
    None = 255
}
struct PDCUTestMessage
{
    string name;
    char id;
    RESPONSE_CODES responseType;
    int numberOfParameters;
    string errorString;
    vector<char> response;
    string param1Name;
    string param2Name;
    string param3Name;
    string param4Name;
    string param5Name;
    boost::function2<bool, vector<char>, PDCUTestMessage &> process;
    // constructors not listed
};
struct ID();
struct Name();
typedef boost::multi_index::multi_index_container<
    PDCUTestMessage,
    boost::multi_index::ordered_unique<
        boost::multi_index::tag<ID>,
        boost::multi_index::member_offset<PDCUTestMessage, char, offsetof(PDCUTestMessage, id)> >,
    boost::multi_index::ordered_unique<
        boost::multi_index::tag<Name>,
        boost::multi_index::member_offset<PDCUTestMessage, string, offsetof(PDCUTestMessage, name)> >
    >
> PDCUMessageList;

后来,我试图为这两把钥匙设置标记,根据VC++6.0编译器特定语法以绕过Get/Tag问题:

typedef index<PDCUMessageList, ID>::type IDIndex;
typedef index<PDCUMessageList, Name>::type NameIndex;

使用上面的代码,我得到了以下错误:

错误C2039:"type":不是引用上面两行typedef的"全局命名空间"的成员。

我通过澄清名称空间解决了这个问题:

typedef boost::multi_index::index<PDCUMessageList, ID>::type IDIndex;
typedef boost::multi_index::index<PDCUMessageList, Name>::type NameIndex;

现在,我在其中一个boost类中出现了另一个错误:lambda_traits.hpp。我没有明确使用lambda_t,所以它必须是使用它的multi_index。以下是错误和位置:

C2039:"access_traits":不是"元组"的成员

lambda_traits:中的第106行

104  template<int N, class T> struct tuple_element_as_reference {
105    typedef typename
106      boost::tuples::access_traits<
107        typename boost::tuples::element<N, T>::type
108      >::non_const_type type;
109  };

有人知道如何克服这个最新的错误吗?

我记得,模板解析在VC6中很尴尬。尽量简化依赖类型。例如:

template<int N, class T> struct tuple_element_as_reference {
  typedef typename boost::tuples::element<N, T>
     tuples_element_t;
  typedef typename tuples_element_t::type
     tuples_element_type_t;
  typedef typename boost::tuples::access_traits<
     tuples_element_type_t
  >
     tuples_access_traits_t;
  typedef typename tuples_access_traits_t::non_const_type
     type;
};