c++ - 当我尝试在 C++ 中使用 lamda 表达式进行排序时出现问题
问题描述
我必须按发现日期订购 Artefact 并打印内容。
我有这门课:
class Artifact{
protected:
int discoveryDate_;
int estimatedDateOfOrigin_;
Artifact::artifactType _artifactType;
Artifact::condition_ _condition;
};
我还有2个派生类GreekArtifact和Egypteam artifact,我创建了GreekArtifact的5个对象和Egypteam artifact的5个对象,并将它们添加到列表中
std::list<Artifact> artifacts;
我试图按发现日期对这个列表进行排序,我这样做了:
std::sort(artifacts.begin(),artifacts.end(),[](auto &a, auto &b){
return a->getDiscoveryDate() > b->getDiscoveryDate();
});
而且这种方法不起作用,我不知道为什么,我真的不明白听起来像这样的错误:
error: no match for 'operator-' (operand types are 'std::_List_iterator<Artifact>' and 'std::_List_iterator<Artifact>')
std::__lg(__last - __first) * 2,
你能帮我弄清楚我做错了什么吗?
解决方案
推荐阅读
- laravel-5 - 如何在 Voyager Laravel 中按用户显示数据
- r - 我正在尝试创建一个随机选择的个体在随机分布中为正,但我的代码不正确
- reactjs - 如何从 React 组件订阅 Redis 频道
- javascript - 从矩阵随机化数组(二维数组)
- angular - 如何在 Angular 2 应用程序的 SCSS 文件中使用动态数据?
- java - 如何在我的项目中的 VS Code 中添加 jar 文件?
- react-native - 无法使用 ReactNative fetch 获取数据
- abap - 在插入数据库表时找出哪些行是重复的?
- oauth-2.0 - 我想将加密密码和解密密码从反应 js 发送到 WSO2 IS 5.9.0?
- sql - 基于 SELECT 和版本化记录的 INSERT INTO