2012-01-18 158 views
3
>c:\program files\microsoft visual studio 10.0\vc\include\algorithm(4494): error C2678:  
binary '=' : no operator found which takes a left-hand operand of type 'const 
std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion) 
      with 
      [ 
       _Elem=char, 
       _Traits=std::char_traits<char>, 
      _Ax=std::allocator<char> 
      ] 
     c:\program files\microsoft visual studio 10.0\vc\include\xstring(707): could be 
'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator = 
(std::basic_string<_Elem,_Traits,_Ax> &&)' 
    with 
     [ 
      _Elem=char, 
      _Traits=std::char_traits<char>, 
      _Ax=std::allocator<char> 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\xstring(762): or  'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)' 
     with 
     [ 
      _Elem=char, 
      _Traits=std::char_traits<char>, 
      _Ax=std::allocator<char> 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\xstring(767): or  
'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator = 
(const _Elem *)' 
    with 
     [ 
      _Elem=char, 
      _Traits=std::char_traits<char>, 
      _Ax=std::allocator<char> 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\xstring(772): or   
'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator = 
(_Elem)' 
    with 
    [ 
      _Elem=char, 
      _Traits=std::char_traits<char>, 
      _Ax=std::allocator<char> 
     ] 
     while trying to match the argument list '(const 
std::basic_string<_Elem,_Traits,_Ax>, const std::basic_string<_Elem,_Traits,_Ax>)' 
     with 
     [ 
      _Elem=char, 
      _Traits=std::char_traits<char>, 
      _Ax=std::allocator<char> 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\algorithm(4522) : see 
reference to function template instantiation '_OutIt 
std::_Set_intersection<_InIt1,_InIt2,_OutIt>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt)' being 
compiled 
     with 
     [ 


_OutIt=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::string,std::less<std ::string>,std::allocator<std::string>,false>>>, 


_InIt1=std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tset_traits<std::string,std::less<std::string>,std::allocator<std::string>,false>>>, 


_InIt2=std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tset_traits<std::string,std ::less<std::string>,std::allocator<std::string>,false>>> 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\algorithm(4549) : see 
reference to function template instantiation '_OutIt 
std::_Set_intersection1<std::_Tree_unchecked_const_iterator<_Mytree>,std::_Tree_unchecked_ 
const_iterator<_Mytree>,_OutIt> 
(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt,std::tr1::true_type)' being compiled 
     with 
     [ 



_OutIt=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::string,std::less<std  ::string>,std::allocator<std::string>,false>>>, 


_Mytree=std::_Tree_val<std::_Tset_traits<std::string,std::less<std::string>,std::allocator< 
std::string>,false>>, 


_InIt1=std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tset_traits<std::string,std 
::less<std::string>,std::allocator<std::string>,false>>>, 

_InIt2=std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tset_traits<std::string,std  ::less<std::string>,std::allocator<std::string>,false>>> 
     ] 
    c:\qc\qc_daq_development\qc\qc_daq\src\hfgui3\expscan.cpp(458) : see reference to 
function template instantiation '_OutIt 

std::set_intersection<std::_Tree_const_iterator<_Mytree>,std::_Tree_const_iterator<_Mytree>  ,std::_Tree_const_iterator<_Mytree>>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt)' being 
compiled 
     with 
     [ 


_OutIt=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::string,std::less<std 
::string>,std::allocator<std::string>,false>>>, 


_Mytree=std::_Tree_val<std::_Tset_traits<std::string,std::less<std::string>,std::allocator< 
std::string>,false>>, 


_InIt1=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::string,std::less<std 
::string>,std::allocator<std::string>,false>>>, 


_InIt2=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::string,std::less<std 
::string>,std::allocator<std::string>,false>>> 

上面提到的是在編譯visual studio 2010程序時拋出的錯誤信息,因爲它在visual studio 2003中運行良好,所以我真的無法弄清楚問題!!!任何幫助或建議將深受讚賞!提前致謝。錯誤:2678,編譯錯誤vs 2010,

我正在粘貼拋出上述錯誤消息的行。 如果有人提供更多信息,請告訴我,如果您花費寶貴的時間幫助我解決問題,我會很感激。 很多感謝

SET_STR::iterator itOut = 
std::set_intersection(setType.begin(),setType.end(),setCategory.begin(),setCategory.end(),s 
etFilter.begin()); 
setFilter.erase(itOut,setFilter.end()); //erase the rest of the set 

Definations:

typedef std::set<string>     SET_STR; 
typedef std::map<string, SET_STR >   MAP_STR_SETSTR; 
typedef std::map<char, SET_STR >   MAP_CHAR_SETSTR; 
typedef std::map<string,SfvarInfo>   MAP_STR_FVARINFO; 


CritSec     m_csVarAccess;     
MAP_STR_VAL    m_mapVar; 
MAP_STR_VAL    m_mapFvarOverrides; 
MAP_STR_VAL    m_mapFvarOrig; 
MAP_STR_FVARINFO  m_mapFvarInfo; 
MAP_STR_SETSTR   m_mapCategoryFvar;    
MAP_CHAR_SETSTR   m_mapTypeFvar;     
MAP_STR_VAL    m_mapLoadedFvar; 

UserParam<string>  m_sScanFvar; 
UserParam<string>  m_sFvarFilterType; 
UserParam<string>  m_sFvarFilterCategory; 

SET_STR setType(m_mapTypeFvar[m_sFvarFilterType.c_str()[0]]); 
SET_STR setCategory(m_mapCategoryFvar[m_sFvarFilterCategory]); 
+0

你可以請包括SET_STR,setType,setCategory,setFilter的定義嗎? – 2012-01-18 03:51:08

+0

謝謝pragnar請讓我知道如果我錯過了什麼! – user1107855 2012-01-18 13:05:08

回答

3

不能分配給該元素指向一個迭代到std::set,因爲這將改變在該元素的「放置」設置(在一般情況下)。所以你不能使用setFilter.begin()作爲set_intersection()調用的輸出迭代器,因爲set_intersection()通過迭代器分配。

基本上,set::iterator總是在VS2010中是const_iterator。我不再安裝VS2003,所以我不能測試,但我猜測那時情況並非如此,所以它編譯。

用std :: insert_iterator <>代替:

std::set_intersection(setType.begin(), setType.end(), 
         setCategory.begin(), setCategory.end(), 
         inserter(setFilter, setFilter.begin())); 

這將是你的set_intersection()調用後做erase()複雜化,因爲現在set_intersection()將返回insert_iterator<>而不是set<>::iterator。從的代碼你發佈了,看起來你希望setFilter的最終內容只包含交集中的元素,所以只要確保setFilter爲空時調用set_intersection(),並且不需要erase()操作。

斯科特邁爾斯談論這種事情在「有效STL」,「項目22:避免原地修改關鍵在setmultiset」,其中包括一些編譯器將如何使用const_iterator風格的迭代器std::set

+0

謝謝micheal,但我無法按照您的有用建議。我是vC++的新手,所以請以可能的語法幫助我。 – user1107855 2012-01-18 13:07:43

+1

當你嘗試時,你會得到什麼錯誤?使用std :: inserter(...)並添加行#include 2012-01-18 15:39:54

+0

pragnar說了什麼,再加上你需要刪除賦值給'SET_STR :: iterator itOut'和因此'erase()'調用。 – 2012-01-18 16:30:31