c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)

If you will place your definitions in this order then the code will be compiled The definition of function doSomething requires the complete definition of class Ball because it access its data member. In your code example module Player.cpp has no access to the definition of class Ball so the compiler issues an error.

What are forward declarations in C++?

Why forward-declare is necessary in C++ The compiler wants to ensure you haven’t made spelling mistakes or passed the wrong number of arguments to the function. So, it insists that it first sees a declaration of ‘add’ (or any other types, classes, or functions) before it is used. This really just allows the compiler to … Read more

c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)

If you will place your definitions in this order then the code will be compiled The definition of function doSomething requires the complete definition of class Ball because it access its data member. In your code example module Player.cpp has no access to the definition of class Ball so the compiler issues an error.