컴파일러 용 파서를 작성하고 있습니다.C++ 생성자 오류
//constructor
Parser::Parser(char* file)
{
MyLex(file) ;
}
사용하여 컴파일시 g ++ parsy.cpp의 parsydriver.cpp, 나는 그러나 말을이 오류가 무엇입니까 : 그래서 생성자 나는 코드가 어디에서 잘못 가고
parsy.cpp: In constructor ‘Parser::Parser(char*)’:
parsy.cpp:13: error: no matching function for call to ‘Lex::Lex()’
lexy2.h:34: note: candidates are: Lex::Lex(char*)
lexy2.h:31: note: Lex::Lex(const Lex&)
parsy.cpp:15: error: no match for call to ‘(Lex) (char*&)’
를? Lex myLex은 파서 헤더에으로 개인으로 선언되었습니다. 나는 지혜롭게 끝나고있다. 나는 이것을 사용하여 시도 :
//constructor
Parser::Parser(char* file):myLex(file)
{
}
내 어휘 분석기 생성자는 다음과 같습니다
Lex::Lex(char* filename): ch(0)
{
//Set up the list of reserved words
reswords[begint] = "BEGIN";
reswords[programt] = "PROGRAM";
reswords[constt] = "CONST";
reswords[vart] = "VAR";
reswords[proceduret] = "PROCEDURE";
reswords[ift] = "IF";
reswords[whilet] = "WHILE";
reswords[thent] = "THEN";
reswords[elset] = "ELSE";
reswords[realt] = "REAL";
reswords[integert] = "INTEGER";
reswords[chart] = "CHAR";
reswords[arrayt] = "ARRAY";
reswords[endt] = "END";
//Open the file for reading
file.open(filename);
}
하지만, 이것은 어휘 분석기 파일과 기능에 대한 정의되지 않은 참조의 무리를 만듭니다! 파일을 올바르게 포함 시켰습니다. 그러나 지금까지이 문제를 극복하는 방법을 이해하지 못했습니다.
UPDATE 헤더 파일 흠은 다음과 같습니다
parsy.h 파일 :
#ifndef PARSER_H
#define PARSER_H
// other library file includes
#include "lexy2.h"
class Parser
{
}...
parsy.cpp 파일 :
// usual ilbraries
#include "parsy.h"
using namespace std ;
Parser::Parser(char* file) ....
parsydriver.cpp :
// usual libraries
#include "parsy.h"
using namespace std ;
int main()
..
lexy2.cpp 파일 :
lexy2.h 파일을 포함 시켰습니다. 어휘 분석기에 파서 헤더 파일을 포함시켜야합니까? 가능성이없는 것 같습니다. 그런데 어떻게 내가 그걸 다루어야합니까?
두 번째 방법은 적절한 방법입니다. 문제는 처음 일한 후에도 여전히 존재할 것입니다. 그것들은 어떤 형태로든 올바르게 링크되지 않은 링커 오류입니다. – chris
어떻게 링커 오류를 극복 할 수 있습니까? 나는 헤더 파일을 포함시키는 질문을 편집하고 업데이트 할 것이다. – thestralFeather7
선택하십시오 : http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – chris