2012-01-18 155 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