错误C2582:'operator ='功能不可用。 (xutility)

时间:2011-11-10 12:16:21

标签: c++

我在'xutility'类中出现错误 - 它被锁定,因为我没有创建它

error C2582: 'operator =' function is unavailable in 'Agent'

错误指向代码中的这些行:

    // TEMPLATE FUNCTION move
template<class _InIt,
class _OutIt> inline
_OutIt _Move(_InIt _First, _InIt _Last,
    _OutIt _Dest, _Nonscalar_ptr_iterator_tag)
{   // move [_First, _Last) to [_Dest, ...), arbitrary iterators
for (; _First != _Last; ++_Dest, ++_First)
    *_Dest = _STD move(*_First); // this line has the error
return (_Dest);
}

为什么会这样?它是什么意思,我该如何解决?

编辑 - 这是我从输出中抓取的,有人可以帮我理解这个吗?很抱歉成为一个完整的新手...

1>------ Build started: Project: D3D10DEMO, Configuration: Debug Win32 ------
1>  Level.cpp
1>c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\level.cpp(449): warning     C4018: '<' : signed/unsigned mismatch
1>  Brain.cpp
1>c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.cpp(43): warning C4413: 'Brain::nodes' : reference member is initialized to a temporary that doesn't persist after the  constructor exits
1>          c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(34) : see declaration of 'Brain::nodes'
1>c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.cpp(43): warning C4413: 'Brain::roomNodeVectors' : reference member is initialized to a temporary that doesn't persist after the constructor exits
1>          c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(35) : see declaration of 'Brain::roomNodeVectors'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2514): error C2582: 'operator =' function is unavailable in 'Agent'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2535) : see   reference to function template instantiation '_OutIt std::_Move<_InIt,_OutIt> (_InIt,_InIt,_OutIt,std::_Nonscalar_ptr_iterator_tag)' being compiled
1>          with
1>          [
1>              _OutIt=Agent *,
1>              _InIt=Agent *
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1170) : see reference to function template instantiation '_OutIt std::_Move<Agent*,Agent*>(_InIt,_InIt,_OutIt)' being compiled
1>          with
1>          [
1>              _OutIt=Agent *,
1>              _InIt=Agent *
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1165) : while compiling class template member function 'std::_Vector_iterator<_Myvec> std::vector<_Ty>::erase(std::_Vector_const_iterator<_Myvec>)'
1>          with
1>          [
1>              _Myvec=std::_Vector_val<Agent,std::allocator<Agent>>,
1>              _Ty=Agent
1>          ]
1>          c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(41) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=Agent
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2514): error C2582: 'operator =' function is unavailable in 'Pickup'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2535) : see reference to function template instantiation '_OutIt std::_Move<_InIt,_OutIt>(_InIt,_InIt,_OutIt,std::_Nonscalar_ptr_iterator_tag)' being compiled
1>          with
1>          [
1>              _OutIt=Pickup *,
1>              _InIt=Pickup *
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1170) : see reference to function template instantiation '_OutIt std::_Move<Pickup*,Pickup*>(_InIt,_InIt,_OutIt)' being compiled
1>          with
1>          [
1>              _OutIt=Pickup *,
1>              _InIt=Pickup *
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1165) : while compiling class template member function 'std::_Vector_iterator<_Myvec> std::vector<_Ty>::erase(std::_Vector_const_iterator<_Myvec>)'
1>          with
1>          [
1>              _Myvec=std::_Vector_val<Pickup,std::allocator<Pickup>>,
1>              _Ty=Pickup
1>          ]
1>          c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(44) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=Pickup
1>          ]
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

2 个答案:

答案 0 :(得分:1)

您似乎正在调用标准库的函数模板,其类型为Agent,无法移动分配,但调用的算法需要这样做。

正如Als在对您的问题的评论中所说,您需要显示调用此算法的代码。

答案 1 :(得分:0)

当然,您需要提供代理类。

假设C ++ 11,您需要实现

struct Agent
{
    // .... other stuff
    Agent(Agent&& other) { /* ... */ }
    Agent& operator=(Agent&& other) { /* ... */ return *this; }
};

,称为Move Assignment运算符。当你在它的时候,你可能想要实现移动构造函数,因为它们是相辅相成的:

    Agent(Agent&& other) { /* ... */ }

推荐阅读:

和其他许多人