I'm having trouble figuring out how I would replace a value in my vector once it is found by the if statement.
void ExprTree::setVariable(const string& s, double d)
{
vector<Variable>::iterator pos;
for(pos = varList.begin(); pos!= varList.end(); ++pos)
{
if(pos->data = s) ; //here is where i'm stuck
else if(pos == varList.end()) varList.push_back(Variable(s,d));
}
}
also, when I try to compile my code I get
ExprTree.h:31: error: ISO C++ forbids declaration of vector with no type
ExprTree.h:31: error: invalid use of ::
ExprTree.h:31: error: expected ; before < token
#include <iostream>
#include <string>
struct TNode
{
std::string data;
TNode* left;
TNode* right;
TNode(const std::string&);
};
class ExprTree
{
private:
TNode* root;
std::vector<Variable> varList; //here is the problem.
void inTrav(TNode* current) const;
void postTrav(TNode* current) const;
void destroyTree(TNode*);
double evaluate(TNode*) const;
public:
ExprTree();
ExprTree(const std::string&);
ExprTree(const ExprTree&);
~ExprTree();
void clear();
ExprTree& operator=(const ExprTree &);
void build(const std::string&);
double evaluate() const;
void printInorder() const;
void printPostorder() const;
void printLevel() const;
void setVariable(const std::string&, double);
double getVariable(const std::string&) const;
void printVariables() const;
};
#endif
last but not least, is this makefile correct?
# Compiler variables
CCFLAGS = -ansi -Wall
# Rule to link object code files to create executable file
assign3: assign3.o ExprTree.o Variable.o
g++ $(CCFLAGS) -o assign3 assign3.o ExprTree.o Variable.o
# Rules to compile source code files to object code
assign3.o: assign3.cpp ExprTree.h
g++ $(CCFLAGS) -c assign3.cpp
Variable.o: Variable.cpp Variable.h
g++ $(CCFLAGS) -c Variable.cpp
ExprTree.o: ExprTree.cpp ExprTree.h
g++ $(CCFLAGS) -c ExprTree.cpp
# Pseudo-target to remove object code and executable files
clean:
-rm *.o assign3