简体   繁体   English

错误:“&”令牌之前的预期“)”

[英]Error: expected ')' before '&' token

I'm having a problem with the constructor signature in the header below. 我在下面的标题中遇到了构造函数签名的问题。 The compiler gives me the message: 编译器给我消息:

 error: expected ')' before '&' token 

But I have no idea why this error happens, I don't think the reason is that the compiler indicates. 但是我不知道为什么会发生此错误,我不认为原因是编译器指出了这一点。

#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

Hint: what's wrong here? 提示:这是怎么了?

#ifndef TextQuery
#define TextQuery

// ..

class TextQuery {
   // ...
};

#endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM