I'm writing a little game that works on a 2D tileset. The idea is that there will be some cells (position X, position Y) where if the player steps, it will trigger an event, so I'm creating a map<cell_position, function to trigger>
.
The problem is that this function it will be in the World
class, that contains the Npc
member, and I want to store the Npc public function teleport
as the value from the map, as I can display in the next snippet:
std::unordered_map<std::pair<int, int>, std::function<void()>> actionCells =
{ std::make_pair(10, 1), std::bind(mPlayerNpc->teleport, 3, 3)) };
Is this possible to do? Because I'm getting the next errors:
error: invalid use of non-static member function 'void Npc::teleport(int, int)'
--Edit-----------------------------------
If I don't want to use a Lambda, is it done like this?
std::unordered_map<std::pair<int, int>, std::function<void()>> actionCells =
{ std::make_pair(10, 1), [&]() {mPlayerNpc->teleport(3, 3); } };