Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ unordered_map causing compile-time error

I have the following:

#include<iostream>
#include<unordered_map>
#include<tuple>

using namespace std;

class CTest {
    // Properties
    public:
        unordered_map<const string, tuple<int, int> > Layout;
    // Methods
    public:
        CTest ();
        ~CTest ();
};

CTest::CTest () {
    Layout["XYZ"] = make_tuple (0, 1);
}

CTest::~CTest () {
  // Do nothing
}

int main (int argc, char *argv[]) {
    CTest Test;
    return 0;
}

Compiling this simple programme gives the following error:

error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion)

I'm using Visual Studio 2010 Professional in Windows 7.

like image 764
Shredderroy Avatar asked Jan 16 '12 20:01

Shredderroy


1 Answers

In addition to changing Layout to:

unordered_map<string, tuple<int, int> > Layout;

as stated by Johan and Benjamin you also need to #include <string>.

Note, I do not understand why the change to Layout is required, even if the const is superfluous.

like image 92
hmjd Avatar answered Sep 20 '22 12:09

hmjd