Why do I need to use forward declarations for a class when I am already including the relevant header file? It has fixed my problem but confused me!
essentially clas
A viceversa relation between classes always needs at least one forward declaration. You can define only a class at a time, so when you define the first class the second is undefined so far. Including headers is not enough, because those headers should also be including each others. Including a file is no different than pasting its contents at the include location. With that in mind, how would you declare two classes that refer to each other within a single file? The answer, as you already know, is forward declarations.