65,189
社区成员




QueryResult TextQuery::query( const string &sought) const
{
static shared_ptr<set<line_no>> nodata(new set<line_no>);
auto loc = wm.find(sought);
if (loc == wm.end())
return QueryResult (sought, nodata, file);
else
return QueryResult(sought, loc->second, file);
}
class QueryResult
{
friend ostream & print(ostream &, const QueryResult&);
using line_no = vector<string>::size_type;
public:
QueryResult(string s, shared_ptr<set<line_no>> p, shared_ptr<vector<string>> f) :
sought(s), lines(p), file(f) {}
private:
string sought; //查询单词
shared_ptr<set<line_no>> lines;
shared_ptr<vector<string>> file;
};
#include <string>
#include <iostream>
using namespace std;
class MyClass{
string _str;
public:
MyClass(string str):_str(str)
{};
string print()
{
return _str;
}
};
MyClass fun(const string &s)
{
return MyClass(s);
}
int _tmain(int argc, _TCHAR* argv[])
{
string* s = new string("foo");
MyClass m = fun(*s);
delete s;
cout<<m.print()<<endl;
return 0;
}
QueryResult(string s, shared_ptr<set<line_no>> p, shared_ptr<vector<string>> f) :
sought(s), lines(p), file(f) {}
class QueryResult
{
friend ostream & print(ostream &, const QueryResult&);
using line_no = TextQuery::line_no;
public:
QueryResult(const string s, shared_ptr<set<line_no>> p, shared_ptr<vector<string>> f) :
sought(s), lines(p), file(f) {}
private:
string sought; //查询单词
shared_ptr<set<line_no>> lines;
shared_ptr<vector<string>> file;
};
class TextQuery
{
public:
using line_no = vector<string>::size_type;
TextQuery(ifstream &);
QueryResult query(const string&) const;
private:
shared_ptr<vector<string>> file;
map <string, shared_ptr<set<line_no>>> wm;
};
QueryResult TextQuery::query( const string& sought) const
{
static shared_ptr<set<line_no>> nodata(new set<line_no>);
auto loc = wm.find(sought);
if (loc == wm.end())
return QueryResult(sought, nodata, file);
else
return QueryResult(sought, loc->second, file);
}}
以上是两个类的定义,和发生错误的函数。
我按照版主说的把构造函数中的参数改成引用或者非引用都是不匹配,也试了把query函数传递的参数sought改成引用或者非引用。结果都是不匹配。