我面临着奇怪的问题。在2008版和VS 2010 调试和Dubug Unicode 版本中,代码工作正常,但无法在发布和发布Unicode 中编译。 可能是什么原因。
此代码正在生成错误
struct bitset_extractor
{
typedef std::forward_iterator_tag iterator_category;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef ptrdiff_t difference_type;
bitset_extractor(const boost::dynamic_bitset<T>& bs, T *buffer)
: bs_(bs), buffer_(buffer), current_(0)
{}
bitset_extractor(const bitset_extractor& it)
: bs_(it.bs_), buffer_(it.buffer_), current_(it.current_)
{}
T& operator*()
{
return buffer_[current_];
}
bitset_extractor& operator++()
{
++current_;
return *this;
}
private:
void operator=(T const&); // unimplemented
const boost::dynamic_bitset<T>& bs_;
T * const buffer_;
unsigned int current_;
};
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(275): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'bitstream::bitset_extractor<T>' (or there is no acceptable conversion)
1> with
1> [
1> T=uint8_t
1> ]
1> C:\vikram\Project\Seurat\src\app\logitech\LogiRTP\Library\Filters\plc\common\bitstream.h(195): could be 'void bitstream::bitset_extractor<T>::operator =(const T &)'
1> with
1> [
1> T=uint8_t
1> ]
1> while trying to match the argument list '(bitstream::bitset_extractor<T>, bitstream::bitset_extractor<T>)'
1> with
1> [
1> T=uint8_t
1> ]
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(2176) : see reference to function template instantiation '_Iter &std::_Rechecked<_OutIt,_OutIt>(_Iter &,_UIter)' being compiled
1> with
1> [
1> _Iter=bitstream::bitset_extractor<uint8_t>,
1> _OutIt=bitstream::bitset_extractor<uint8_t>,
1> _UIter=bitstream::bitset_extractor<uint8_t>
1> ]
1> C:\vikram\Project\Seurat\3rdparty\boost\boost/dynamic_bitset/dynamic_bitset.hpp(1090) : see reference to function template instantiation '_OutIt std::copy<std::_Vector_const_iterator<_Myvec>,BlockOutputIterator>(_InIt,_InIt,_OutIt)' being compiled
1> with
1> [
1> _OutIt=bitstream::bitset_extractor<uint8_t>,
1> _Myvec=std::_Vector_val<unsigned char,std::allocator<uint8_t>>,
1> BlockOutputIterator=bitstream::bitset_extractor<uint8_t>,
1> _InIt=std::_Vector_const_iterator<std::_Vector_val<unsigned char,std::allocator<uint8_t>>>
1> ]
1> C:\vikram\Project\Seurat\src\app\logitech\LogiRTP\Library\Filters\plc\common\bitstream.h(210) : see reference to function template instantiation 'void boost::to_block_range<uint8_t,std::allocator<_Ty>,bitstream::bitset_extractor<T>>(const boost::dynamic_bitset<Block> &,BlockOutputIterator)' being compiled
1> with
1> [
1> _Ty=uint8_t,
1> T=uint8_t,
1> Block=uint8_t,
1> BlockOutputIterator=bitstream::bitset_extractor<uint8_t>
1> ]
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(275): error C2582: 'operator =' function is unavailable in 'bitstream::bitset_extractor<T>'
1> with
1> [
1> T=uint8_t
1> ]
答案 0 :(得分:3)
问题是你的bitset_extractor
被用作迭代器,但它不能满足迭代器的所有要求。
std::copy
函数在尝试将原始迭代器转换为已检查的迭代器时,使用两个operator=
对象调用bitset_extractor<uint8_t>
。由于用户定义的迭代器不存在已检查的迭代器,因此检查的迭代器类型和原始迭代器类型是相同的,从而导致正在使用的迭代器的常规副本。
罪魁祸首是_Rechecked
函数,用于将常规迭代器转换为已检查的迭代器。这取决于迭代器调试级别,以不同方式完成;这就是你的Debug构建工作的原因,但不是你的Release版本,因为它们默认具有不同的迭代器调试级别。
解决方案是为operator=
实施bitset_extractor
。如果要将它用作迭代器,必须支持其类型的迭代器所需的所有功能。
禁用已检查的迭代器无济于事。无论你做什么,你的迭代器仍将通过_Rechecked
函数。
答案 1 :(得分:0)
问题解决了。我在VS Project Setting-&gt;预处理器中添加了_SECURE_SCL = 1。
工作正常。