麻烦帮忙看看以下这个c++函数要怎么写?

virual Listing sort(string field); 

要求:
This is a new method. This method returns a copy of the
invoking Listing object sorted by the field name given in the parameter. Use an
appropriate STL sorting function to sort the advertisements. To sort based on
the field name given by the parameter field, consider using an
STL sort function that uses a predicate to determine object equality. The field
names that can be passed into this function are "email,"
"start," "close," and "quantity." 

其中listing中的其他定义我也给出来
#ifndef LISTING_H
#define LISTING_H
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <functional>
#include "Advertisement.h"
using namespace std;
class Listing;
class Listing {
protected:
typedef vector<Advertisement*> Container;
public:
typedef Container::iterator iterator;
protected:
Container objects;
public:
virtual ~Listing() {};
virtual Advertisement* operator[](const int& number);
virtual void add(Advertisement* ptr);
virtual iterator begin();
virtual iterator end();
// return a sorted copy of this Listing
virtual Listing sort(string field);
// return a filtered by keyword copy of this Listing
virtual Listing filter(string keyword);
};
#endif

慕桂英4014372
浏览 197回答 2
2回答

湖上湖

直接使用objects对象的add. begin(). end()等方法。filter 实现 采用 std::remove_if接口,使用函数对象sort 实现 采用 std::qsort() 接口

慕田峪7331174

这是一个新的方法。该方法返回一个对象排序的字段名在参数调用上市的副本。使用适当的STL排序函数进行排序的广告。根据给定的参数字段的字段名进行排序,可以考虑使用的STL排序功能,使用谓词来确定对象的平等。传递到该函数的字段名可以是“电子邮件”,“开始”,“关闭”和“量”。
打开App,查看更多内容
随时随地看视频慕课网APP