C++primer练习12.33
练习12.33
为QueryResult类添加begin和end成员,返回lines的指定位置,再添加get_file成员,返回成员file的shared_ptr指针
#ifndef QUERYRESULT #define QUERYRESULT #include <string> #include <vector> #include <stdlib.h> #include <map> #include <set> #include <memory> using std::string; using std::vector; using std::map; using std::set; using std::shared_ptr; class TextQuery; class QueryResult{ public: typedef vector<string>::size_type line_no; friend class TextQuery; QueryResult(string s,shared_ptr<set<line_no>> p,shared_ptr<vector<string>> text):sword(s),lines(p),paragraph(text){} set<line_no>::const_iterator begin(){return lines->cbegin(); } set<line_no>::const_iterator end(){return lines->cend(); } shared_ptr<vector<string>> get_file(){return paragraph; } string sword; shared_ptr<set<line_no>> lines; shared_ptr<vector<string>> paragraph; private: }; #endif