【发布时间】:2017-04-22 01:56:50
【问题描述】:
#include <functional>
#include <string>
using namespace std;
int main()
{
function<long(const string&, size_t, int)> fn = stol;
}
上面的代码无法按预期编译,出现以下错误:
错误:没有用于初始化 'std::function
' 的匹配构造函数(又名 'function , 分配器 > &, unsigned long long, int)>')
【问题讨论】:
-
首先,this
std::stolreference 应该会有所帮助。记下这些论点,并将它们与你的比较。 -
std::stol()的第二个参数是一个size_t*指针,而不是像你这样的size_t值。
标签: c++ function c++11 constructor type-conversion