I need to use function eval
sometimes, but compiler throws an error: Error: variable
firstOperand cannot be read at compile time
.
import std.array;
import std.format;
public class BinaryOperatorExpression
{
private
{
string operator;
Expression firstExpr;
Expression secondExpr;
}
public final this(T)(string operator, T firstExpr, T secondExpr)
{
this.operator = operator;
this.firstExpr = firstExpr;
this.secondExpr = secondExpr;
}
override public double eval()
{
double firstOperand = firstExpr.eval();
double secondOperand = secondExpr.eval();
return mixin(
format("%d %s %d", firstOperand, operator, secondOperand)
);
}
}
Type T
exactly has eval
returning double'. How can I make
firstOperandand
secondOperand` static?