我无法编译C++ 11中的简单程序。 你可以在这里看看http://cpp.sh/9muxf。C++ std :: function operator =
#include <functional>
#include <iostream>
#include <exception>
#include <tuple>
#include <map>
using namespace std;
typedef int Json;
typedef string String;
class Integer/*: public PluginHelper*/
{
public:
Json display(const Json& in)
{
cout << "bad" << endl;
return Json();
}
map<String, function<Json(Json)>>* getSymbolMap()
{
static map<String, function<Json(Json)>> x;
auto f = bind(&Integer::display, this);
x["display"] = f;
return nullptr;
}
};
问题在行x["display"] = f;
你有很大的帮助,如果你让我明白发生了什么在这里:)到来。 Can std::function
不能被复制?
没有编译器或许发出错误讯息? – juanchopanza
有些人认为绑定现在没用了,因为有lambda/closures,所以考虑'auto f = [this](Json j) - > Json {return display(j);};'作为替代 – PeterT
您需要'#include ' –