错误 C2582:'运算符='函数在“bitstream::bitset_extractor”中不可用对比2010年

发布于 2025-01-07 09:33:47 字数 3990 浏览 0 评论 0原文

我遇到了奇怪的问题。相同的代码在 vs 2008 和 VS 2010 Debug and 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>          ]

I am facing strange problem.Same code is working fine in vs 2008 and VS 2010 Debug and Dubug Unicode Version but failed to compile in Release and Release Unicode.
What could be the reason for this.

This code is generating the error

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>          ]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

德意的啸 2025-01-14 09:33:47

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

std::copy 函数在尝试将原始迭代器转换为已检查迭代器时,正在使用两个 bitset_extractor 对象调用 operator= 。由于用户定义的迭代器不存在已检查的迭代器,因此已检查的迭代器类型和原始迭代器类型相同,从而导致使用迭代器的常规副本。

罪魁祸首是_Rechecked函数,它用于将常规迭代器转换为检查迭代器。根据迭代器调试级别,此操作的完成方式有所不同;这就是为什么您的调试版本可以工作,但发布版本却不能,因为默认情况下它们具有不同的迭代器调试级别。

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

禁用已检查的迭代器不会有帮助。无论您做什么,您的迭代器仍将执行 _Rechecked 函数。

The problem is that your bitset_extractor is being used as an iterator, but it doesn't meet all of the requirements for an iterator.

The std::copy function is calling operator= with two bitset_extractor<uint8_t> objects as it attempts to convert the original iterator into a checked iterator. Since no checked iterator exists for user defined iterators, the checked iterator type and original iterator type are the same, resulting in a regular copy of the iterator being used.

The culprit is the _Rechecked function, which is used to convert a regular iterator into a checked iterator. This is done differently, depending on the iterator debug level; that's why your Debug build works, but not your Release build, as they have different iterator debug levels by default.

The solution is to implement operator= for bitset_extractor. If you want to use it as an iterator, it must support all of the functionality required for an iterator of it's type.

Disabling checked iterators won't help. Your iterators will still go through the _Rechecked function, no matter what you do.

羅雙樹 2025-01-14 09:33:47

问题解决了。我在VS项目设置->预处理器中添加了_SECURE_SCL=1。

它运行良好。

Problem is solved .I added _SECURE_SCL=1 in VS Project Setting->preprocessor.

It is working fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文