2010-12-15 19 views
3

multi_index_containerを使いこなそうとしていて、奇妙なコンパイラエラーが発生しています。まずは、私の問題を示すための最も単純な例です愚かな単純なもの)...ブースト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; 
} 

グラムで報告されたエラー++(GCC 4.4.4、Linuxの)です:

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

私はクラステンプレートにコンテナを変換するまで、だから、これは素晴らしい仕事をしていました、その後、私はこのエラーを取得し、理由を解決することはできません..

任意のアイデアが...

+0

を理解されるであろう、私は実際に起こっていることですが、VC2010は、コードの罰金をコンパイルする理由はわかりません! – AraK

+0

@AraK、これはgcc odityだと思いますが、@skwllspの解決策は今はうまくいきます! – Nim

答えて

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

ARRGH ...私はそれが簡単かもしれないと思った!これはテンプレート/ typename地獄です...私は実際にあきらめて '(_cSet)を取得 'を使用しましたが、私はこれに戻ります。どうも! – Nim

+0

@ニム:しないでください、無料の機能は行く方法です:) –

+0

@Metthieu、本当に?しかし、メンバー関数が、フリー関数ができないかもしれない実装の詳細を利用することができますか? – Nim

関連する問題