Question : Can a C++ class declare instances of itself without having to use 'void *' ?

Given a simple class, the following does not work because the compiler does not yet know what "TestClass" is:

class TestClass
{
public:
  TestClass *AnotherInstance;
}

To make it work, "AnotherInstance" must be declared void (in the header).   All further references to "AnotherInstance" then have to be typecast like this:   (TestClass *)AnotherInstance

Question: Since the typecasting gets very annoying and verbose . . . is there a way to make the compiler accept something more like the first example above?

Thanks.

Answer : Can a C++ class declare instances of itself without having to use 'void *' ?

>> So my question really is:  how can I tell the compiler that Class2 will be defined later.
If you preceed the two classes with forward references, as in:
class Class2;
class Class1;
then your code in http:#33219489 compiles. If you start getting into compilation issues as you add items to your classes, then just remember that you can have two header files, one for each class, and two .cpp files - again, one for each class; and that may help you out of any difficulties.
Random Solutions  
 
programming4us programming4us