I am using Xcode 10.3 developer for a C++ project and after fixing my declaration, when I go to run it says build failed with the four errors at the bottom. The file with the main is under the two other files. I have attached the screenshot of the errors as well.
#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);
}
The header file variable.h is:
#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;
};
module.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 == ',');
}
errors: Showing Recent Issues :-1: Undefined symbol: parseName(std::__1::basic_stringstream, std::__1::allocator >&) Showing Recent Issues :-1: Undefined symbol: SymbolTable::init() Showing Recent Issues :-1: Undefined symbol: SymbolTable::insert(std::__1::basic_string, std::__1::allocator >, int) Showing Recent Issues :-1: Undefined symbol: SymbolTable::lookUp(std::__1::basic_string, std::__1::allocator >) const