Hello.
i have a composite which i want to delete. this is a composite which
represents a boolean expression (see a previous post of mine with more
details at http://groups.google.ca/groups?hl=en...%26scoring%3Dd
)
VariableExp *x = new VariableExp("X");
VariableExp *y = new VariableExp("Y");
BooleanExp expression(
new OrExp(
new AndExp(new Constant(true), x),
new AndExp(x, y) ) );
represents the expression
(TRUE AND X) OR (X AND Y)
i have defined destructors for these dervied expressions as follows:
AndExp::~AndExp()
{
if (_operand1) {
delete _operand1;
_operand1 = 0;
}
if (_operand2) {
delete _operand2;
_operand2 = 0;
}
}
OrExp::~OrExp()
{
if (_operand1) {
delete _operand1;
_operand1 = 0;
}
if (_operand2) {
delete _operand2;
_operand2 = 0;
}
}
NotExp::~NotExp()
{
if (_operand) {
delete _operand;
_operand = 0;
}
}
for deleting the expression this way
delete expression;
i know this doesn't do the job, as the second AndExp in my example
here doesn't know that the first AndExp already deleted the
VariableExp x, and it tries to delete it - causing an error for
double-deleting.
my question is, how do I avoid it? what technique should i use to
delete the composite properly?
TIA,
Matan Nassau