我面临着奇怪的problem.Same代码在vs 2008和VS 2010 Debug和Dubug 版本中运行良好,但是在发布和发布的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> ]发布于 2012-02-20 12:24:04
问题是您的bitset_extractor被用作迭代器,但它并不能满足迭代器的所有要求。
std::copy函数使用两个bitset_extractor<uint8_t>对象调用operator=,因为它试图将原始迭代器转换为检查迭代器。由于用户定义的迭代器不存在检查迭代器,所以检查迭代器类型和原始迭代器类型是相同的,因此将使用迭代器的常规副本。
罪魁祸首是_Rechecked函数,它用于将常规迭代器转换为检查迭代器。这是不同的操作,取决于迭代器调试级别;这就是为什么debug构建可以工作,而不是发行版构建,因为在默认情况下,它们有不同的迭代器调试级别。
解决方案是为operator=实现bitset_extractor。如果要将其用作迭代器,则必须支持其类型的迭代器所需的所有功能。
禁用检查过的迭代器不会有帮助。不管您做什么,迭代器仍将遍历_Rechecked函数。
发布于 2012-02-21 07:34:47
解决了.I在VS项目设置->预处理器中添加了_SECURE_SCL=1的问题.
它很好用。
https://stackoverflow.com/questions/9357699
复制相似问题