【发布时间】:2012-01-05 02:49:20
【问题描述】:
我正在尝试在 C++11 中使用 lambda 函数实现映射
std::map<int, int, [](const int&a, const int& b) { return a < b; }> test;
但是失败了
错误:
‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’模板参数列表中参数 3 的类型/值不匹配错误:期望一个类型,得到
‘{}’错误:
‘;’令牌之前的声明类型无效
有什么建议吗?
【问题讨论】:
-
你提供了一个 lambda,即一个对象;模板参数必须是 type,而不是类型的实例。