0

g++ エラーがわかりません。簡単なコードをコンパイルしてみます:

#include <string>

#include <boost/interprocess/sync/interprocess_mutex.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <boost/interprocess/containers/list.hpp>
#include <boost/interprocess/containers/map.hpp>

namespace BIP = boost::interprocess;

using std::pair;
using std::less;
using std::char_traits;

class Edge {
    public:
        typedef BIP::managed_shared_memory::segment_manager segment_manager_t;
        typedef BIP::allocator<void, segment_manager_t> void_allocator_t;
        typedef BIP::allocator<char, segment_manager_t> char_allocator_t;
        typedef BIP::basic_string<char, char_traits<char>, char_allocator_t> char_string_t;
        typedef BIP::vector<char_string_t, char_allocator_t> vector_string_t;

        Edge(long int endNodeId, const char_allocator_t & alloc);
        Edge();
        Edge(const Edge & other);
        ~Edge();

        void addComment(const std::string & comment);

        private:
            vector_string_t comments;
            long int endNodeId;
            int count;
};

inline void Edge::addComment(const std::string & comment) {
    char_string_t newComment(comment.c_str(), comments.get_allocator());

    comments.push_back(newComment); **// all is good without this line**
}

g++ 出力 (gcc バージョン 4.7.3 (Debian 4.7.3-4)):

 In file included from /usr/include/boost/interprocess/containers/vector.hpp:19:0,
                     from forStackOverflow.hpp:6:
    /usr/include/boost/container/vector.hpp: In instantiation of ‘void boost::container::vector<T, Allocator>::priv_push_back(const T&) [with T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]’:
    /usr/include/boost/container/vector.hpp:1371:4:   required from ‘void boost::container::vector<T, Allocator>::push_back(T&) [with T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]’
    forStacknckOverflow.hpp:45:31:   required from here
    /usr/include/boost/container/vector.hpp:1788:92: error: no matching function for call to ‘boost::container::container_detail::insert_copy_proxy<boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >, boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >
>*>::insert_copy_proxy(boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >&, const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >&)’
    /usr/include/boost/container/vector.hpp:1788:92: note: candidates are:
    In file included from /usr/include/boost/container/vector.hpp:50:0,
                     from /usr/include/boost/interprocess/containers/vector.hpp:19,
                     from forStackOverflow.hpp:6:
    /usr/include/boost/container/detail/advanced_insert_int.hpp:132:4: note: boost::container::container_detail::insert_copy_proxy<A, Iterator>::insert_copy_proxy(A&, const value_type&) [with A = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; Iterator = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >*; boost::container::container_detail::insert_copy_proxy<A, Iterator>::value_type = char]
    /usr/include/boost/container/detail/advanced_insert_int.hpp:132:4: note:   no known conversion for argument 2 from ‘const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >’ to ‘const value_type& {aka const char&}’
    /usr/include/boost/container/detail/advanced_insert_int.hpp:126:8: note: boost::container::container_detail::insert_copy_proxy<boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >, boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >*>::insert_copy_proxy(const boost::container::container_detail::insert_copy_proxy<boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >, boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >*>&)
    /usr/include/boost/container/detail/advanced_insert_int.hpp:126:8: note:   candidate expects 1 argument, 2 provided
    In file included from /usr/include/boost/interprocess/segment_manager.hpp:33:0,
                     from /usr/include/boost/interprocess/detail/managed_memory_impl.hpp:26,
                     from /usr/include/boost/interprocess/managed_shared_memory.hpp:21,
                     from forStackOverflow.hpp:4:
    /usr/include/boost/interprocess/allocators/allocator.hpp: In instantiation of ‘void boost::interprocess::allocator<T, SegmentManager>::construct(const pointer&, const P&) [with P = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; T = char; SegmentManager = boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index>; boost::interprocess::allocator<T, SegmentManager>::pointer = boost::interprocess::offset_ptr<char, long int, long unsigned int, 0ul>]’:
    /usr/include/boost/preprocessor/iteration/detail/local.hpp:37:1:   recursively required from ‘static void boost::container::allocator_traits<Alloc>::priv_construct_dispatch2(boost::true_type, Alloc&, T*, const P0&) [with T = char; P0 = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Alloc = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; boost::true_type = boost::integral_constant<bool, true>]’
    /usr/include/boost/preprocessor/iteration/detail/local.hpp:37:1:   required from ‘static void boost::container::allocator_traits<Alloc>::priv_construct(boost::false_type, Alloc&, T*, const P0&) [with T = char; P0 = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Alloc = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; boost::false_type = boost::integral_constant<bool, false>]’
    /usr/include/boost/preprocessor/iteration/detail/local.hpp:37:1:   required from ‘static void boost::container::allocator_traits<Alloc>::construct(Alloc&, T*, const P0&) [with T = char; P0 = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Alloc = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]’
    /usr/include/boost/container/vector.hpp:1781:10:   required from ‘void boost::container::vector<T, Allocator>::priv_push_back(const T&) [with T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]’
    /usr/include/boost/container/vector.hpp:1371:4:   required from ‘void boost::container::vector<T, Allocator>::push_back(T&) [with T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]’
    forStackOverflow.hpp:45:31:   required from here
    /usr/include/boost/interprocess/allocators/allocator.hpp:263:7: error: cannot convert ‘const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >’ to ‘boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >::value_type {aka char}’ in initialization

53 行をコメントすると、エラーが消えます。clang コンパイラを試してみましたが、役に立ちませんでした。ありがとう!

編集: すべてのエラー メッセージを追加します。

4

1 に答える 1

3

エラー メッセージから、a から aboost::container::basic_stringへの変換エラーがあることがわかります。const char&

エラー メッセージはさらに、アロケータがプッシュバックされる新しいオブジェクトにメモリを割り当てようとしているブースト ヘッダー内の場所を示しています。

void priv_push_back(const T &x)
   {
      if (this->m_holder.m_size < this->m_holder.capacity()){
         //There is more memory, just construct a new object at the end
         allocator_traits_type::construct
            ( this->m_holder.alloc()
            , container_detail::to_raw_pointer(this->m_holder.start() + this->m_holder.m_size)
            , x );
         ++this->m_holder.m_size;
      }
      else{
         container_detail::insert_copy_proxy<Allocator, T*> proxy(this->m_holder.alloc(), x);
         this->priv_forward_range_insert_no_capacity(vector_iterator_get_ptr(this->cend()), 1, proxy, alloc_version());
      }
   }

ここで問題が発生します。この関数の型 T はboost::interprocess::basic_stringであるため、 への呼び出しが発生すると、型 を宣言したアロケーターにallocator_traits_type::constructa を渡そうとします。boost::interprocess::basic_stringchar

typedef BIP::allocator<char, segment_manager_t> char_allocator_t;
typedef BIP::vector<char_string_t, char_allocator_t> vector_string_t;

文字列のベクトルは文字列を割り当てたいので、ベクトルには char アロケータの代わりに文字列アロケータが必要です。

于 2013-09-23T03:23:58.640 に答える