Below is a simplified version of something I am trying to do.
I am getting a C2678 error on the return line of getMove2()
. The only difference between getMove()
and getMove2()
is const
.
I have a work-around (commented-out line), but I'm trying to understand why that line doesn't work, and how else to fix it.
#include <string>
#include <map>
class Dummy
{
public:
Dummy(std::string character, int a, int b, int c) {
name = character;
moves["a"] = a;
moves["b"] = b;
moves["c"] = c;
}
int getMove(std::string move_name) {
return moves[move_name];
}
int getMove2(std::string move_name) const {
return moves[move_name];
//return moves.find(move_name)->second; //This works but I can't figure out how to make the above work
}
private:
std::string name;
std::map <std::string, int> moves;
};
I have tried playing around with having different pieces of the map
as const
, but no luck.