I'm attempting to use a map to store functions to be called at certain times.
typedef std::function<void(rapidjson::Document&)> Callback;
std::map<std::string, Callback> _callbackDict = {
{ "foo", HandleFoo },
{ "bar", HandleBar },
};
When I attempt to store them it leads to an error:
error: could not convert '{{"foo", ((FooBar*)this)->FooBar::HandleFoo}, {"bar", ((FooBar*)this)->FooBar::HandleBar}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, std::function<void(int, int)> >'
MCVE
#pragma once
#include <map>
#include <iostream>
#include <functional>
typedef std::function<void(int, int)> Callback;
class FooBar
{
private:
std::map<std::string, Callback> _callbackDict = {
{ "foo", HandleFoo },
{ "bar", HandleBar },
};
public:
FooBar();
void HandleFoo(int a, int b);
void HandleBar(int a, int b);
~FooBar();
};