我正在为 C++ 项目使用 Xcode 10.3 开发人员,在修复我的声明后,当我运行它时,它说构建失败,底部有四个错误。带有 main 的文件位于另外两个文件下。我还附上了错误的屏幕截图。
#include <strstream>
#include <vector>
using namespace std;
#include "expression.h"
#include "operand.h"
#include "variable.h"
#include "symboltable.h"
//create an object of SymbolTable
extern SymbolTable symbolTable;
//definition of the function evaluate()
int Variable::evaluate()
{
//return the name from the symbolTable
return symbolTable.lookUp(name);
}
头文件 variable.h 是:
#include <strstream>
#include <vector>
using namespace std;
//define the class Variable subclass of the Operand
class Variable : public Operand
{
public:
//define the constructor
Variable(string name)
{
this->name = name;
}
//define the function evaluate()
int evaluate();
private:
string name;
};
模块.cpp
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
#include "expression.h"
#include "subexpression.h"
#include "symboltable.h"
#include "parse.h"
//create an object of SymbolTable
SymbolTable symbolTable;
//prototype of the function
void parseAssignments(stringstream& in);
//define main function
int main(){
//Variables
Expression* expression;
char paren, comma;
string line;
//create input file stream
ifstream fin("input.txt");
//check if the file is open
//if file is not open error message
if(!fin.is_open())
perror("error with opening file!");
//create loop to read from file content
while(getline(fin, line)){
symbolTable.init();
if(!fin)
break;
stringstream in(line, ios_base::in);
in >> paren;
cout << line << " ";
expression = SubExpression::parse(in);
in >> comma;
//call the function
parseAssignments(in);
//display results
int result = expression->evaluate();
cout << "value = " << result << endl;
}
system("pause");
return 0;
}
//define parseAssignments()
void parseAssignments(stringstream& in){
char assignop, delimiter;
string variable;
int value;
symbolTable.init();
do{
variable = parseName(in);
in >> ws >> assignop >> value >> delimiter;
symbolTable.insert(variable, value);
}
while (delimiter == ',');
}
错误:显示最近的问题:-1:未定义的符号:parseName(std::__1::basic_stringstream, std::__1::allocator >&) 显示最近的问题:-1:未定义的符号:SymbolTable::init() 显示最近的问题问题:-1:未定义符号:SymbolTable::insert(std::__1::basic_string, std::__1::allocator >, int) 显示最近的问题:-1:未定义符号:SymbolTable::lookUp(std:: __1::basic_string, std::__1::allocator >) const