У меня возникла проблема с сигнатурой конструктора в заголовке ниже. Компилятор дает мне сообщение:Ошибка: ожидается ')' перед '&' token
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
@Barry разместил [MCVE] в своем ответе. Это то, что мы ожидали от вас. –
Примечание: если вы используете ключевое слово 'register' в C++ (теперь не используется), как говорят имя метода интерфейса, вы получаете ту же ошибку. –