2013-11-01 2 views
2

다음은 내 문제를 표현한 것입니다.할당자를 사용하여 boost :: lockfree :: spsc_queue 사용

오류 C2512 : '부스트 : lockfree :: 자세히 :: runtime_sized_ringbuffer'내가 VS2010에 다음과 같은 오류가이 코드

#include <boost/lockfree/spsc_queue.hpp> 

class test { 
    struct complicated { 
    int x; 
    int y; 
    }; 
    std::allocator<complicated> alloc; 
    boost::lockfree::spsc_queue<complicated, 
    boost::lockfree::allocator<std::allocator<complicated> > > spsc; 
    test(void); 

}; 

test::test(void): spsc(alloc) {}; 

컴파일하는 동안 클래스가 없습니다 적절한 기본 생성자 템플릿 멤버 함수 '부스트 :: lockfree :: spsc_queue :: spsc_queue (const를 표준 : : 할당 < _Ty> &)'

는 하나 개의 인자를 가진 생성자를 컴파일 상태 오류 메시지, 나는 allocator가되어야한다고 믿지만 기본 오류는 기본 생성자에 대해 이야기합니다.

문서 시작 지점은 http://www.boost.org/doc/libs/1_54_0/doc/html/lockfree.html입니다.

boost :: lockfree :: allocator를 사용하여 boost :: lockfree :: spsc_queue를 정의하는 적절한 메커니즘은 무엇입니까? 부스트 소스 코드에 따르면

답변

2

, 당신이 당신의 spsc_queue에 대한 컴파일시 용량을 지정하지 않기 때문에 spsc_queue의 기본 클래스는 다음과 같은 생성자가 runtime_sized_ringbuffer에 형식 정의 및 템플릿 마법을 통해 해결됩니다 :

explicit runtime_sized_ringbuffer(size_t max_elements); 

template <typename U> 
runtime_sized_ringbuffer(typename Alloc::template rebind<U>::other const & alloc, size_t max_elements); 

runtime_sized_ringbuffer(Alloc const & alloc, size_t max_elements); 

보시다시피 이들 모든 생성자는 max_element 매개 변수를 필요로합니다. ,

explicit spsc_queue(size_type element_count): 
    base_type(element_count) 
{ 
    BOOST_ASSERT(runtime_sized); 
} 

template <typename U> 
spsc_queue(size_type element_count, typename allocator::template rebind<U>::other const & alloc): 
    base_type(alloc, element_count) 
{ 
    BOOST_STATIC_ASSERT(runtime_sized); 
} 

spsc_queue(size_type element_count, allocator_arg const & alloc): 
    base_type(alloc, element_count) 
{ 
    BOOST_ASSERT(runtime_sized); 
} 

즉 당신의 spsc_queue 생성자를 호출 할 때 할당과 함께 크기를 제공하려고 : 그를 제공 할 수있는 유일한 방법은 다음 spsc_queue 생성자 중 하나를 사용하는 것입니다.

+0

감사합니다. element_count/max_elements의 목적을보기 위해 runtime_sized_ringbuffer를 더 살펴야합니다. 즉, 시작 카운트인지 최대 카운트인지를 확인해야합니다. 왜냐하면 최대 카운트이기 때문에,이 시점에서 내가 알 수있는 할당 자의 필요성이 정말로 없다. –

+0

코드에 따르면 실제로 최대 요소 수입니다. 'boost :: lockfree :: spsc_queue >'를 사용해 보시기 바랍니다. 나는 이것이 당신의 큐를 컴파일 시간 크기의 링 버퍼를 사용하도록 설정할 것이라고 생각한다. –

관련 문제