【发布时间】:2016-11-18 06:34:38
【问题描述】:
我无法在 C++11 中编译一个简单的程序。 你可以在这里查看http://cpp.sh/9muxf。
#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;一行
如果你能让我理解这里发生的事情,你会很有帮助:)。
std::function不能被复制吗?
【问题讨论】:
-
编译器是否可能发出错误消息?
-
有些人认为 bind 现在没有用了,因为有 lambdas/closures,所以考虑
auto f = [this](Json j)->Json{return display(j);};作为替代 -
你需要
#include <string> -
我不知道为什么但它在这里编译
http://cpp.sh/7w6c -
@Mayank 可能包含在其他 stl 头文件中,例如
iostream。但不能保证。
标签: c++ c++11 stdmap std-function stdbind