当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ boost iterator throwing assert and programme terminates

问题描述:

I get the following error at this line:

const short pcmSample = *reinterpret_cast<const short*>(*(buffer->index));

buffer is an object of class accumlator.

Here I am trying to convert a byte array into shorts. The code throws this runtime error and terminates.

class accumlator : public boost::circular_buffer<char>

{

public:

boost::circular_buffer<char>::iterator index;

};

i have initialized the iterator to point to begin of buffer

and index is a iterator to circular buffer.

boost::cb_details::iterator::reference

boost::cb_details::iterator::operator*() const [with

Buff = boost::circular_buffer, Traits =

boost::cb_details::nonconst_traits >,

boost::cb_details::iterator::reference = char&]:

Assertion `m_it != 0' failed.

i have even tracked this to the file boost/circular_buffer/detail.hpp

the assert condition checks - if iterator is pointing to end.

if it is pointing to end then it throws the assert.

Thanks in advance.

网友答案:

It seems you didn't assign index to a value. The operator* is doing a runtime check to make sure it's pointing to valid (non-0) value.

分享给朋友:
您可能感兴趣的文章:
随机阅读: