Make a function return any derived class type

I want to make a recursive descent parser, and I want to use different functions for the different kinds of grammar the parser will parse, e.g. a ParseStatement function for statements, or a ParseBlock function for a block of code.
The thing is, a ParseExpression function can return different types. If the expression contains an operator, then it will return a type made to store the operator and the operands. But if the expression contains only a number, then ParseExpression should return only that number.
So, what should the return type for ParseExpression be? I thought about making a base class for any item in the tree and make all the other types inherit from it, then set the function's return type to that, but then I won't be able to access any information other than what the base class has.
Is there any way to make a function return a type that won't be the same each time?
Topic archived. No new replies allowed.