A sample question on c++ primer: Add member named get_file
that returns a shared_ptr
to the file in the QueryResult
object.
class QueryResult
{
friend std::ostream& print(std::ostream&, const QueryResult&);
public:
using line_no = std::vector<std::string>::size_type;
QueryResult(std::string s, std::shared_ptr<std::set<line_no>> p, std::shared_ptr<std::vector<std::string>> f) :sought(s), lines(p), file(f) {}
std::set<line_no>::iterator begin(std::string) const { return lines->begin(); };
std::set<line_no>::iterator end(std::string) const { return lines->end(); };
std::shared_ptr<std::vector<std::string>> get_file() const { return std::make_shared<std::vector<std::string>>(file); };
private:
std::string sought;
std::shared_ptr < std::set<line_no>> lines;
std::shared_ptr<std::vector<std::string>> file;
};
compile error:
error C2665: std::vectorstd::string,std::allocator<std::string>::vector: no overloaded function could convert all the argument types.