The following code is in a function and result is a reference to a bool value.
trueValues and false Values are sets of chars that either result in a true or false statement.
stack<bool> operandStack;
for (int k = 0; k < postfix.size(); k++)
{
char ch = postfix[k];
if (ch != '!' && ch != '&' && ch != '|')
{
if (trueValues.contains(ch))
{
operandStack.push(true);
}
if (falseValues.contains(ch))
{
operandStack.push(false);
}
}
else if (ch == '!' || ch == '&' || ch == '|')
{
bool operand2 = operandStack.top();
operandStack.pop();
bool operand1 = operandStack.top();
operandStack.pop();
switch(ch)
{
case '!':
operandStack.push(operand1 != operand2);
case '&':
operandStack.push(operand1 && operand2);
case '|':
operandStack.push(operand1 || operand2);
}
}
}
result = operandStack.top();
Commenting out the result =
line gets rid of the error message.