I am making an expression tree for a school assignment and am getting these error in my code. Being quite new to C++ I have searched the web for answers to no avail.
#include<iostream>
using namespace std;
#include "expression.h"
namespace Student
{
void writeNode(NodeType* node);
/*
Displays an arithmetic expression.
@pre The node is initialized.
@post This node has been displayed.
*/
int answer(NodeType* node);
/*
returns the value of the SUB_NODE, or the value
if node is just an int.
*/
void Expression::display() const
{
writeNode(eTree*); //error here
}
int Expression::getValue() const
{
return answer(eTree*); //error here
}
void writeNode(NodeType node)
{
if(node.tag == SUB_NODE)
{
cout<<"(";
writeNode(node.left);
cout<< node.op;
writeNode(node.right);
cout<<")";
}
else if(node.tag == INT_ONLY)
cout<<node.intValue;
}
int answer(NodeType node)
{
if(node.tag == INT_ONLY)
return node.intValue;
else
{
switch(node.op)
{
case '+':
return answer(node.left) + answer(node.right);
case '-':
return answer(node.left) - answer(node.right);
case '*':
return answer(node.left) * answer(node.right);
case '/':
return answer(node.left) / answer(node.right);
}
}
}
}
The output build is;
1>c:\users\ben\documents\visual studio 2008\projects\test\test\expression1.cpp(34) : error C2059: syntax error : ')'
1>c:\users\ben\documents\visual studio 2008\projects\test\test\expression1.cpp(39) : error C2059: syntax error : ')'
Those are the errors I'm getting at the lines I've specified(lines don't line up to same on here). Any help you could give me would be greatly appreciated.