gpt4 book ai didi

c++ - 错误 : expected ')' before '&' token

转载 作者:太空宇宙 更新时间:2023-11-03 10:40:26 25 4
gpt4 key购买 nike

下面标题中的构造函数签名有问题。编译器给我消息:

error: expected ')' before '&' token

但是我不知道为什么会出现这个错误,我认为原因不是编译器指示的。

#ifndef TextQuery
#define TextQuery

#include <fstream>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <sstream>
#include <vector>

using std::ifstream;
using std::map;
using std::shared_ptr;
using std::set;
using std::string;
using std::istringstream;
using std::vector;

class TextQuery
{
public:
using line_no = vector<string>::size_type;
TextQuery(ifstream &); //!!!!error: expected ')' before '&' token
private:
shared_ptr<vector<string>> file; //input file
//map of each word to the set of the lines in which that word appears
map<string, shared_ptr<set<line_no>>> wm;
};

//read the input file and build the map of lines to line numbers
TextQuery::TextQuery(ifstream &is) : file(new vector<string>)
{
string text;
while(getline(is, text)) { //for each line in the file
file->push_back(text); //remember this line of text
int n = file->size() - 1; //the current line number
istringstream line(text); //separate the line into words
string word;
while(line >> word) { //for each word in that line
//if word isn't already in wm, subscripting adds a new entry
auto &lines = wm[word]; //lines id a shared_ptr
if(!lines) //that pointer is null the first time we see word
lines.reset(new set<line_no>); //allocate a new set
lines->insert(n); //insert this line number
}
}
}

#endif

最佳答案

提示:这里有什么问题?

#ifndef TextQuery
#define TextQuery

// ..

class TextQuery {
// ...
};

#endif

关于c++ - 错误 : expected ')' before '&' token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39587221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com