Question

I have been trying to create an unordered map that takes in (x, y) values as the key to look for its corresponding value.

For example) x=-1 y=0 I would get a certain symbol '$'

I have created the following unordered map:

static boost::unordered_map<pair<char, char>, char> map;

But I am having problems when I try to insert values into the map doing the following:

map.insert({ { '-1', '0' }, '$' });

It doesn't seem like I am getting a correct map.

Whenever I do the following within the lookup of the map I get this:

char temp = map[{'-1','0'}];

temp = '0'

Any help will be much appreciated,

Thank you, Al

Was it helpful?

Solution

'-1' is a multi-character constant, with a value that's probably out of range for char. If you mean to use the values -1 and 0, then remove the quotes.

For portability, if the values might be negative, you should use a type that's guaranteed to be signed (like int or signed char). Otherwise, you might get a surprise if you change to a compiler that gives an unsigned char.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top