MistyD
MistyD

Reputation: 17253

Error while attempting to find an element in a map

I am using the following code

void SomeClass::Update(const std::string& symbol, const int& volume)
{
  std::map<std::string,int>& Refcontainer = BTracker;

  //The two conditionals below seem to cause a problem here

  if(Refcontainer.find(symbol) != Refcontainer.end())
  {
    Refcontainer[symbol] = Refcontainer[symbol] + volume;
  }
  else
  {
    Refcontainer[symbol] = 0 + volume;
  }
}

The errors i am getting are:

Error   16  error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   10  error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string'   c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   11  error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string'   c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   12  error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string'   c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   1   error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   2   error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   3   error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'    c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   13  error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   14  error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   15  error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   7   error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   8   error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   9   error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   4   error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string'   c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   5   error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string'   c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "
Error   6   error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string'   c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xfunctional  125 1   " "

Any suggestion on why I am getting this error and how to resolve it ?

Upvotes: 1

Views: 1845

Answers (2)

Eugene Mamin
Eugene Mamin

Reputation: 749

I should mention that your code can be greatly simplified to

Refcontainer[symbol] += value;

instead all conditions.

Upvotes: 4

Jerry Coffin
Jerry Coffin

Reputation: 490673

You've probably forgotten to #include <string>.

Some of VC++'s other headers (iostream?) include enough of a definition of std::string to let you define an std::string object, but then fail with weird errors like these when you try to do much of anything with it.

Upvotes: 4

Related Questions