I'm writing some test code to get my head around various elements I'm not fluent with yet. I have two classes which references each other through pointers, and to solve that I used forward declarations of the classes, which compiles and runs nicely. However, whenever I try to actually use the pointers in any way, the compiler (GCC 4.2) returns the following errors:
"Forward declaration of struct Foo"
"Invalid use of incomplete type 'struct Foo'"
Here's the line that makes all the noise:
d->sayHello();
In which d is a pointer to an instance of the other class. What is wrong here? And why does gcc suddenly think that the class is a struct?
Structs and Classes are pretty much equivalent in C++. (the struct defines his member as public in default, class does this as private)
If you declare a Class but not define it, you can use Foo as a type. But if you want to access any members (or methods) of the class the compiler needs more information than just the forward declaration.
You need to include a header file with a proper declaration. (or similar)