I am trying to call a function using a std::map
key value pair. I found this stackoverflow article Calling a function depending on a variable? but the solution
std::map<std::string, std::function<void()>> le_mapo;
does not work and results in a error something like "error: lvalue required as unary ‘&’ operand" using it as so
std::map<std::string, std::function<void()>> le_mapo;
le_mapo["ftp"] = &ftp(); // ftp function is in the same class, this function is the constructor
I am trying to call a function in the same class with this method and it results in a lvalue error any idea what to do
I have also tried using at the top
#define BE_EVIL(map, function, x) map[ #x ] = & function ## x
NOTE: i have all the proper includes such as
#include <iostream>
#include <map>
#include <functional>
here is a Reproducible Example
#include <iostream>
#include <map>
#include <functional>
class stackoverflow
{
private:
void ftp();
public:
stackoverflow();
};
void ftp()
{
std::cout << "Minimal reproduction" << std::endl;
}
stackoverflow::stackoverflow()
{
std::map<std::string, std::function<void()>> le_mapo;
le_mapo["ftp"] = &ftp();
}