我正在尝试根据其中一个属性对自定义对象的矢量进行排序,我收到以下错误:
/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));
}
答案 0 :(得分:1)
适用于:
编译器版本:http://rextester.com/
Bost版本: