2012-03-26 4 views
0

ブーストマルチインデックスでシーケンスされたインデックスに関して非常に単純化された質問があります。コードは以下の通りです:ブーストマルチインデックスのシーケンシャルインデックスに挿入する機能を一致させる

私のクラスはLink.hppに保存されている:

#include <string> 

class Link { 
public: 
    Link(std::string l,std::string r) :linkID(l),roadName(r) {} 
    Link() {} 
    std::string roadName; 
    std::string linkID; 

}; 

と主な機能:

#include "Link.hpp" 
#include <string> 
#include <iostream> 
#include <boost/multi_index_container.hpp> 
#include <boost/multi_index/member.hpp> 
#include <boost/multi_index/ordered_index.hpp> 
#include <boost/multi_index/sequenced_index.hpp> 
#include <boost/multi_index/key_extractors.hpp> 

using boost::multi_index::multi_index_container; 
using boost::multi_index::ordered_non_unique; 
using boost::multi_index::ordered_unique; 
using boost::multi_index::sequenced; 
using boost::multi_index::indexed_by; 
using boost::multi_index::member; 

typedef boost::multi_index::multi_index_container<Link, 
     indexed_by<sequenced<> > > Links; 

int main() { 
    Links Ls; 
    Ls.insert(Link("123", "456")); 

    return 1; 
} 

コンパイル、<>が存在し、収量を、配列決定します間違いは分かりません。あなたは私を助けてくれますか?

エラー:

$ g++ Links.cpp 
Links.cpp: In function ‘int main()’: 
Links.cpp:29:29: error: no matching function for call to ‘boost::multi_index::multi_index_container<Link, boost::multi_index::indexed_by<boost::multi_index::sequenced<> > >::insert(Link)’ 
Links.cpp:29:29: note: candidates are: 
/usr/include/boost/multi_index/sequenced_index.hpp:267:28: note: std::pair<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::sequenced_index_node<typename SuperMeta::type::node_type> >, bool> boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::insert(boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::iterator, boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::value_param_type) [with SuperMeta = boost::multi_index::detail::nth_layer<1, Link, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<Link> >, TagList = boost::mpl::vector0<mpl_::na>, typename SuperMeta::type::node_type = boost::multi_index::detail::index_node_base<Link, std::allocator<Link> >, boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::iterator = boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::sequenced_index_node<boost::multi_index::detail::index_node_base<Link, std::allocator<Link> > > >, boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::value_param_type = const Link&] 
/usr/include/boost/multi_index/sequenced_index.hpp:267:28: note: candidate expects 2 arguments, 1 provided................... 
+0

あなたが試みることができる: 'Ls.insert(Ls.begin()、リンク(「123」、「456」)); – Ylisar

+0

@Ylisar正しいです。それは働いた、thanx – rahman

答えて

3

insertは、最初の引数としてイテレータはどこに挿入するコンテナ内で指定することを期待。 multi_index_containerにもpush_backがあるようですが、これはおそらくあなたが望むものに近いでしょう。だから、シーケンスの先頭に挿入する

Ls.insert(Ls.begin(), Link("123", "456")); 

それとも背面の:

Ls.push_back(Link("123", "456")); 
+0

なぜ両方の答えを1つに含めないでください。両方のソリューションが機能しました。ありがとう – rahman

+0

確かに、私はスニペットを追加することができます:) – Ylisar

関連する問題