【发布时间】:2014-05-04 10:41:57
【问题描述】:
我正在尝试根据其中一个属性对自定义对象的向量进行排序,但出现以下错误:
/usr/include/boost/lambda/detail/function_adaptors.hpp:264:15:错误:从“const int”类型的表达式中对“int&”类型的引用进行无效初始化 make: * [src/boost_lambda.o] 错误 1
关于这个错误的任何想法?你可以在这里找到代码:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
struct Parent{
int getAge(){
return age;
}
int age;
std::string name;
};
int main()
{
std::vector<Parent> aListParents;
Parent aParent1;
aParent1.age=1;
aParent1.name="parent1";
Parent aParent2;
aParent2.age=2;
aParent2.name="parent2";
aListParents.push_back(aParent1);
aListParents.push_back(aParent2);
std::sort(aListParents.begin(), aListParents.end(),
bind(&Parent::age, boost::lambda::_1) < bind(&Parent::age, boost::lambda::_2));
}
【问题讨论】:
-
@JoachimPileborg Boost lambda 从表达式生成函数对象。
-
@juanchopanza 这不是
boost::bind,而是boost::lambda::bind。
标签: c++ sorting boost lambda bind