missing ';' before identifier 'f'

Hi i got this problem:

class Expression
{
public:
Expression(void);
~Expression(void);
.
.
.
private:
Function f;
};

class Function : public Expression
{
public:
.
.
.
};

The problem is caused cause i m tryin to put a Function object on Expression class which base class is Expression???
I believe class Function is not defined prior to your Function f; statement so the compiler does not know which type you are trying to declare there.
There's no way that will work. The size of Function depends on the size of Expression. The size of an objects is the sum of the sizes of its members, which means that the size of Expression in turn depends on the size of Function.
The only way to resolve the circular dependency is to make Expression::f a Function *.

Still, that will not compile until you forward-declare Function before defining Expression:
class Function;
You can't do that.

To have a `Function` object in `Expression` you must have the complete definition of `Function`,
That is not possible because `Function` needs a complete definition of `Expression` as it derives from it.

You can have a pointer to `Function` if you forward declare that class
Thanks you guys. I also thought that was the problem but i wanted to ask more expririenced people.

I ll make a post for another question in a while.
Topic archived. No new replies allowed.