我有
typedef std::queue<MyObject*> InputQueue;
std::vector<InputQueue> inp_queue;
inp_queue[1].push(new MyObject());
等。
我要编译它,但它的核心立即转储。我想我需要先将队列实际添加到向量中(它们不像地图那样自动创建)。如何添加队列而不将其作为指向队列的指针?
编辑:
我应该指出,我使用的队列类不是std::queue,而是这个:
http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
我没想到编译器会抱怨,否则我会事先声明的。
g++ test.cpp
In file included from /usr/include/c++/4.4/deque:63,
from /usr/include/c++/4.4/queue:61,
from concurrentqueue.h:3,
from test.cpp:1:
/usr/include/c++/4.4/bits/stl_construct.h: In function âvoid std::_Construct(_T1*, const _T2&) [with _T1 = concurrent_queue<Packet*>, _T2 = concurrent_queue<Packet*>]â:
/usr/include/c++/4.4/bits/stl_uninitialized.h:187: instantiated from âstatic void std::__uninitialized_fill_n<<anonymous> >::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = concurrent_queue<Packet*>*, _Size = long unsigned int, _Tp = concurrent_queue<Packet*>, bool <anonymous> = false]â
/usr/include/c++/4.4/bits/stl_uninitialized.h:223: instantiated from âvoid std::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = concurrent_queue<Packet*>*, _Size = long unsigned int, _Tp = concurrent_queue<Packet*>]â
/usr/include/c++/4.4/bits/stl_uninitialized.h:318: instantiated from âvoid std::__uninitialized_fill_n_a(_ForwardIterator, _Size, const _Tp&, std::allocator<_Tp2>&) [with _ForwardIterator = concurrent_queue<Packet*>*, _Size = long unsigned int, _Tp = concurrent_queue<Packet*>, _Tp2 = concurrent_queue<Packet*>]â
/usr/include/c++/4.4/bits/stl_vector.h:1035: instantiated from âvoid std::vector<_Tp, _Alloc>::_M_fill_initialize(size_t, const _Tp&) [with _Tp = concurrent_queue<Packet*>, _Alloc = std::allocator<concurrent_queue<Packet*> >]â
/usr/include/c++/4.4/bits/stl_vector.h:230: instantiated from âstd::vector<_Tp, _Alloc>::vector(size_t, const _Tp&, const _Alloc&) [with _Tp = concurrent_queue<Packet*>, _Alloc = std::allocator<concurrent_queue<Packet*> >]â
test.cpp:18: instantiated from here
/usr/include/c++/4.4/bits/stl_construct.h:74: error: no matching function for call to âconcurrent_queue<Packet*>::concurrent_queue(const concurrent_queue<Packet*>&)â
concurrentqueue.h:12: note: candidates are: concurrent_queue<Packet*>::concurrent_queue()
concurrentqueue.h:12: note: concurrent_queue<Packet*>::concurrent_queue(concurrent_queue<Packet*>&)