I don't know what it is that I'm missing. It looks simple enough, but has eluded me for a couple days.
I've tried five or six ways to initialize an unordered map, getting the same error every time.
Data Structures
#include <unordered_map>
using namespace std;
struct InStruct{
InStruct(char readchr, int currentState) {
this->readchar = readchr;
this->currentState = currentState;
}
InStruct() = default;
InStruct(InStruct&) = default;
char readchar;
int currentState;
};
struct OutStruct {
OutStruct(char writechar, bool moveleft, int newstate) {
this->writechar = writechar;
this->moveleft = moveleft;
this->newstate = newstate;
}
OutStruct() = default;
OutStruct(OutStruct&) = default;
char writechar;
bool moveleft;
int newstate;
};
Main:
int main() {
const unordered_map<InStruct, OutStruct>& turingmap {
std::make_pair(InStruct('B', 1), OutStruct('B', false, 5)),
std::make_pair(InStruct('a', 1), OutStruct('B', false, 2)),
std::make_pair(InStruct('a', 2), OutStruct('a', false, 2)),
std::make_pair(InStruct('b', 2), OutStruct('b', false, 2)),
std::make_pair(InStruct('B', 2), OutStruct('B', true, 3)),
std::make_pair(InStruct('b', 3), OutStruct('B', true, 2)),
std::make_pair(InStruct('a', 4), OutStruct('a', true, 4)),
std::make_pair(InStruct('b', 4), OutStruct('b', true, 4)),
std::make_pair(InStruct('B', 4), OutStruct('B', false, 1))
};
return 0;
}
Error C2440 'initializing': cannot convert from 'initializer list' to 'const std::unordered_map,std::equal_to<_Kty>,std::allocator>> &' TuringMachine c:\users\apaz\source\repos\turingmachine\turingmachine\source.cpp 152