2011-11-10 19 views
-1

- 私は、コードに次の行にそれエラーC2582: 'operator ='関数は使用できません。 (xutility)私は「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); 
} 

これはなぜ発生しますか?それはどういう意味ですか、どうすれば修正できますか?

EDIT - これは出力から取得したものです。誰かがこれを理解するのに役立つことができますか?完全な初心者です...

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

あなたが提供したコードを呼び出して、*あなたの*コードを表示する必要があります。 –

+2

行に**エラー**がありません。それは_detects_エラーとコンパイラ_reports_それはその行で検出されたように – sehe

+0

テンプレートに関する面白いことは、エラー報告がそれらにちょっと混乱しているということです。特定のクラスには存在しない 'operator ='という機能を使用しようとしていますが、コンパイラはクラスのgucky内部を見るまでこれを検出できません。クラスのあなたの_usage_に集中し、その文書に細心の注意を払ってください。 –

答えて

1

あなたは移動ライブラリを割り当てることができないタイプのAgentの標準ライブラリの関数テンプレートを使用しますが、呼び出されるアルゴリズムはそれだけで済みます。

あなたの質問にAlsが言ったように、このアルゴリズムを呼び出すコードを表示する必要があります。

+0

コードのどの部分がアルゴリズムを呼び出すのか分かりません。私は何を探していますか? – SirYakalot

+0

@Sir:エラーメッセージから、VCを使用しているようです。テンプレートインスタンシエーションスタックが表示され、エラーの原因となったコードの行を見つけることができます。 – sbi

+0

テンプレートのインスタンシエーションスタックはどこですか?私はこれを探す場所がわからない。ありがとう。 – SirYakalot

0

もちろん、エージェントクラスを用意する必要があります。 C++ 11と仮定すると

は、あなたが移動代入演算子として知られている

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

を実装する必要があります。

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

推奨読書:

あなたがそれに取り組んでいる一方で、彼らが手に手を行くと、あなたは移動のコンストラクタを実装する場合があります

その他多数

+1

"need"?コピー代入演算子を実装するにはまだ十分だと思われます。 – MSalters

+0

@MSalters:私たちはクラスも呼び出しコードも持っていません。表示された機能テンプレート(_Move)は文書化されていません。 'std :: move'の出力イテレータには、セマンティクスの移動を意味する出力イテレータが割り当てられています。あなたはコピーコンストラクタがユーザにとって十分であるかもしれないことは間違いありません。 – sehe

関連する問題