Two things - one, you need semicolons after class declarations:
class class1{ class2 *x; }; class class2{ class1 *x; };
Two, you can create a declaration before class definitions. This tells the compiler that this class exists, and you have not defined it yet. In this case, place the class2 before the definition of class1 :
class class2 ; class class1{ class2 *x; }; class class2{ class1 *x; };
source share