This is a continuation of this question c++ function ptr in unorderer_map, compile time error
I was trying to use std::function
instead function pointer, and I can insert function only if the functions are static. otherwise I will get following error
main.cpp:15:11: error: no matching member function for call to 'insert'
map.insert(std::make_pair("one",&Example::procesString));
#include<string>
#include <unordered_map>
#include<functional>
namespace Test
{
namespace Test
{
class Example
{
public:
Example()
{
map.insert(std::make_pair("one",&Example::procesString));
}
static void procesString(std::string & aString)
//void procesString(std::string & aString) -> compiler error
{
}
static void processStringTwo(std::string & aString)
{
}
std::unordered_map<std::string,std::function<void(std::string&)>> map;
};
}
}
int main()
{
return 0;
}
Aucun commentaire:
Enregistrer un commentaire