Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误:应为';)';在'之前&';代币_C++_C++11_Header_Ifstream - Fatal编程技术网

C++ 错误:应为';)';在'之前&';代币

C++ 错误:应为';)';在'之前&';代币,c++,c++11,header,ifstream,C++,C++11,Header,Ifstream,我对下面标题中的构造函数签名有问题。编译器给我的信息是: 但是我不知道为什么会发生这个错误,我不认为原因是编译器指出的 #ifndef TextQuery #define TextQuery #include <fstream> #include <map> #include <memory> #include <set> #include <string> #include <sstream> #include <

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

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

#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
#定义文本查询
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用std::ifstream;
使用std::map;
使用std::shared_ptr;
使用std::set;
使用std::string;
使用std::istringstream;
使用std::vector;
类文本查询
{
公众:
使用line\u no=vector::size\u type;
TextQuery(ifstream&);/!!错误:在“&”标记之前应为“)”
私人:
共享的\u ptr文件;//输入文件
//将每个单词映射到该单词出现的行集合
map-wm;
};
//读取输入文件并构建线到行号的映射
TextQuery::TextQuery(ifstream&is):文件(新向量)
{
字符串文本;
而(getline(is,text)){//用于文件中的每一行
file->push_back(文本);//记住这行文本
int n=file->size()-1;//当前行号
istringstream行(文本);//将行分隔为单词
字符串字;
while(line>>单词){//
//如果word不在wm中,订阅会添加一个新条目
auto&lines=wm[word];//行id a共享\u ptr
if(!lines)//第一次看到word时,该指针为null
line.reset(新集合);//分配一个新集合
行->插入(n);//插入此行号
}
}
}
#恩迪夫

提示:这里怎么了

#ifndef TextQuery
#define TextQuery

// ..

class TextQuery {
   // ...
};

#endif

提示:这里怎么了

#ifndef TextQuery
#define TextQuery

// ..

class TextQuery {
   // ...
};

#endif

@巴里在他们的回答中发表了一篇文章。这就是我们所期望的。注意:如果你在C++中使用关键字“登记”(现在不使用),比如说接口方法名称,你会得到同样的错误。@巴里在他们的答案中贴了一个字母。如果你在C++中使用关键字“登记”(现在未使用),比如说接口方法名称,你会得到同样的错误。解决问题的方法是:使用<代码> >语法>曾经是< /C> >,或者使用<代码>·IFNDEF TeXQueRyGyH。或者使用
#ifndef TextQuery\u h