When I was trying to write a library for myself that handles the algebraic expressions I encountered a problem. I have three classes: divide, expression, groupexpression. I want to use divide type in expression and group expression. And use expression type in group expression. The problem is I also need to use group expression type in divide class like this:
// * (2x)/(4b)
class Divide{
//...
GroupExpression numerator, denumerator;
//...
}
// * -2Pow(x, 3)
class Expression{
//...
Divide pow, multiple;
//...
}
// * (2x-3ax+Pow(x, 5))/(ax-2x)
class GroupExpression : Divide{
//...
vector<Expression> group;
//...
}
But this does not meet with programing rules that we should declare it first to use it. How to sort this to meet the rules?
I've been thinking about the exception but didn't found any answer. Didn't find any solution on internet because I don't know how to search this problem so I appreciate any help.
Is it possible doing this this?