2016-09-20 4 views
1

아래 헤더의 생성자 서명에 문제가 있습니다. 컴파일러는 나에게 메시지를 준다 :Error : expected ')'before '&'토큰

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 
+2

@ 배리가 답변에 [MCVE]를 올렸습니다. 그것이 우리가 당신에게서 기대했던 것입니다. –

+1

참고 : 인터페이스 메소드 이름과 같이 C++ (현재 사용되지 않음)에서 'register'키워드를 사용하는 경우에도 동일한 오류가 발생합니다. –

답변

7

힌트 : 무엇이 잘못 되었나요?

#ifndef TextQuery 
#define TextQuery 

// .. 

class TextQuery { 
    // ... 
}; 

#endif 
+0

문제를 해결하는 우아한 방법 :'#pragma once'를 사용하거나'#ifndef TextQuery_h'를 사용하십시오. – PanicSheep

+0

고마워. 답을 읽은 후에 코드를 수정했습니다. –