gpt4 book ai didi

c++ - 错误 C2582: 'operator =' 函数在 'bitstream::bitset_extractor VS 2010 中不可用

转载 作者:太空狗 更新时间:2023-10-29 21:27:18 25 4
gpt4 key购买 nike

我遇到了一个奇怪的问题。相同的代码在 vs 2008 和 VS 2010 Debug 和 Dubug Unicode 版本中运行良好,但在 Release 和 Release 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> ]

最佳答案

问题是你的 bitset_extractor被用作迭代器,但它不满足迭代器的所有要求。

std::copy函数正在调用 operator=有两个bitset_extractor<uint8_t>对象,因为它试图将原始迭代器转换为已检查的迭代器。由于用户定义的迭代器不存在检查迭代器,检查迭代器类型和原始迭代器类型相同,导致使用迭代器的常规拷贝。

罪魁祸首是 _Rechecked函数,用于将常规迭代器转换为检查迭代器。根据迭代器调试级别,这是不同的做法;这就是为什么您的 Debug 构建有效,但您的 Release 构建无效,因为默认情况下它们具有不同的迭代器调试级别。

解决方案是实现operator=对于 bitset_extractor .如果您想将它用作迭代器,它必须支持其类型的迭代器所需的所有功能。

禁用已检查的迭代器无济于事。您的迭代器仍将通过 _Rechecked功能,无论你做什么。

关于c++ - 错误 C2582: 'operator =' 函数在 'bitstream::bitset_extractor<T> VS 2010 中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9357699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com