Confused about Forward Referencing with classes

I'm a little confused about forward referencing. If I'm not mistaken, this should work, correct?

1
2
3
4
5
6
7
8
9
10
class Y;  //Forward Reference
class X : public Y
{

};

class Y
{

};


When I use this code, I get the following error:
'Y' : base class undefined

I know I'm doing something wrong, but not sure what. Thoughts?
You're doing nothing wrong.

Forward definitions of classes (and structs) only work for pointers.

1
2
3
4
5
6
7
8
9
10
class Y;  //Forward Reference
class X
{
    Y* pY;
};

class Y
{

};


So a base class must always be defined before one derived from it.

P.S. That should be pointers and references.
Last edited on
Ah! Exactly what I needed. Thanks!
Topic archived. No new replies allowed.