gpt4 book ai didi

c++ - Boost multi_index_container,通过标签获取索引导致编译错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:32:23 30 4
gpt4 key购买 nike

因此,我正在尝试使用 multi_index_container 并且遇到了一个相当奇怪的编译器错误,首先这是演示我的问题的最简单的示例(我可能遗漏了一些非常简单的东西) ...

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/mem_fun.hpp>

namespace multi_index = boost::multi_index;

template <typename _IdType>
class A
{
public:
typedef _IdType IdType;
IdType getId() const { return id; }

private:
IdType id;
};

struct id_index{};

template <typename Traits>
class Container
{
typedef typename Traits::AType AType;
typedef typename AType::IdType IdType;

typedef typename multi_index::multi_index_container<
AType,
multi_index::indexed_by<
// sort by Id
multi_index::ordered_non_unique<multi_index::tag<id_index>, BOOST_MULTI_INDEX_CONST_MEM_FUN(AType, IdType, getId) >
>
> ASet;

typedef typename ASet::template index<id_index>::type::const_iterator a_it;
typedef typename ASet::template index<id_index>::type::reverse_iterator a_rit;

typedef typename ASet::template index<id_index>::type id_index_t;

public:

bool addA(AType const& cA)
{
const id_index_t& os = _cSet.get<id_index>(); // line 1: errors occur here
// .. do stuff
return true;
}

private:
// Instance of the container...
ASet _cSet;
};

struct ATraits
{
typedef A<int> AType;
};

int main(void)
{
Container<ATraits> container;

ATraits::AType a;

container.addA(a);

return 0;
}

g++(gcc 4.4.4,linux)报错是:

error: expected primary-expression before ‘>’ token (@ line 1)
error: expected primary-expression before ‘)’ token (@ line 1)

所以在我将 Container 转换为类模板之前一切正常,在此之后,我收到此错误,并且无法弄清楚原因..

任何想法将不胜感激......

最佳答案

  bool addA(AType const& cA)
{
const id_index_t& os = _cSet.template get<id_index>(); // line 1: errors occur here
// .. do stuff
return true;
}

关于c++ - Boost multi_index_container,通过标签获取索引导致编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4451444/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com