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

mentionnés ci-dessus est le message d'erreur lancé lors de la compilation du programme avec Visual Studio 2010, car il fonctionne bien dans visual studio 2003, donc je suis vraiment incapable de comprendre le problème!!! toute aide ou suggestion sera grandement appréciée !!! Merci d'avance.erreur: 2678, erreur de compilation vs 2010,

Je colle la ligne qui lance l'erreur ci-dessus msg. Dans le cas où quelqu'un de plus d'informations, s'il vous plaît faites le moi savoir, je vous serai reconnaissant si vous passez votre temps précieux à m'aider à le réparer. Un grand merci à l'avance

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

Pouvez-vous inclure les définitions de SET_STR, setType, setCategory, setFilter? –

+0

Merci pragnar s'il vous plaît laissez-moi savoir si je manque quelque chose !! – user1107855

Répondre

3

Vous ne pouvez pas attribuer à l'élément pointé par un itérateur dans un std::set parce que cela changerait le « placement » de cet élément dans la ensemble (dans le cas général). Vous ne pouvez donc pas utiliser setFilter.begin() comme itérateur de sortie pour l'appel set_intersection(), car set_intersection() l'affecte via l'itérateur.

Fondamentalement, set::iterator est toujours un const_iterator dans VS 2010. Je n'ai plus VS2003 installé, donc je ne peux pas tester, mais je suppose qu'à l'époque ce n'était pas le cas, donc compilé.

Utilisez un std :: insert_iterator <> à la place:

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

Cela va compliquer la erase() que vous faites après l'appel set_intersection() depuis set_intersection() retournera maintenant insert_iterator<> au lieu d'un set<>::iterator .De le code vous avez posté, il semble que vous voulez que le contenu final de setFilter ne contienne que les éléments de l'intersection, alors assurez-vous que setFilter est vide lorsque set_intersection() est appelée, et que l'opération erase() n'est pas nécessaire.

Scott Meyers parle de ce genre de chose dans « STL efficace », « Point 22: Eviter en place une modification clé dans set et multiset », y compris la façon dont certains compilateurs utiliseront const_iterator itérateurs -style pour std::set.

+0

merci micheal, mais je ne suis pas en mesure de suivre votre suggestion utile. Je suis nouveau à vC++, alors s'il vous plaît aidez-moi avec la syntaxe possible. – user1107855

+1

Quelle erreur obtenez-vous lorsque vous essayez? Utilisez std :: inserter (...) et ajoutez la ligne #include

+0

Ce que dit pragnar, plus vous devrez supprimer l'affectation à 'SET_STR :: iterator itOut' et donc l'appel' erase() ' . –