If you will place your definitions in this order then the code will be compiled
class Ball; class Player { public: void doSomething(Ball& ball); private: }; class Ball { public: Player& PlayerB; float ballPosX = 800; private: }; void Player::doSomething(Ball& ball) { ball.ballPosX += 10; // incomplete type error occurs here. } int main() { }
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.
Related Posts:
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- Linker Error C++ “undefined reference ” [duplicate]
- What are the differences between a pointer variable and a reference variable in C++?
- Expression must have class type
- Why is enum class preferred over plain enum?
- Why am I getting this redefinition of class error?
- What are forward declarations in C++?
- Single class has a Class Redefinition Error
- C++ Linked List Node with class
- What does `*&` in a function declaration mean?
- (->) arrow operator and (.) dot operator , class pointer
- Pass a vector by reference C++
- Difference between const reference and normal parameter
- Separating class code into a header and cpp file
- how to define -std=c++11 as default in g++
- Pointer to incomplete class type is not allowed
- Why am I getting this redefinition of class error?
- no default constructor exists for class
- Is the practice of returning a C++ reference variable evil?
- Getting error “a nonstatic member reference must be relative to a specific object” while both member are in the same class
- Error “C++ requires a type specifier for all declarations whilst defining methods”
- What are the differences between struct and class in C++?
- error C2011: ” : ‘class’ type redefinition
- The compiler is complaining about my default parameters?
- C++ Linked List Node with class
- Getting error: ISO C++ forbids declaration of with no type
- initial value of reference to non-const must be an lvalue
- error: member access into incomplete type : forward declaration of
- “Implicit instantiation of undefined template” when forward declaring template class
- “used without template parameters”
- Error: No instance of constructor matches the argument list
- expected constructor, destructor, or type conversion before ‘(’ token
- C++ Class ‘undeclared identifier”
- Base class undefined
- Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11?
- What is the meaning of a C++ Wrapper Class?
- error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
- Reference to non-static member function must be called
- Does C++11 have C#-style properties?
- C++ Return value, reference, const reference
- G++ undefined reference to class::function
- Creating an instance of class
- C++ pass an array by reference
- How to create a vector of class objects in C++?
- expected primary-expression before ‘]’ token
- Is null reference possible?
- Why can’t I make a vector of references?
- Is C++ Array passed by reference or by pointer?
- error C2039: ‘string’ : is not a member of ‘std’, header file problem
- istream and ostream problem – C++
- Struct with template variables in C++
- error: no member function declared in class
- Here is some error with my .h file which show [Error] unterminated #ifndef when I include my class template in it
- Error: invalid use of member in static member function
- Is “delete this” allowed in C++?
- What is a segmentation fault?
- How many spaces for tab character(\t)?
- How to create a dynamic array of integers
- How to create a dynamic array of integers
- How do I build a graphical user interface in C++? [closed]
- C++ convert from 1 char to string?
- How do I build a graphical user interface in C++? [closed]
- convert a char* to std::string
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- How to implement 2D vector array?
- Why the switch statement cannot be applied on strings?
- What is the difference between g++ and gcc?
- How to use setprecision in C++
- How to dynamically allocate arrays in C++
- What does (~0L) mean?
- How to dynamically allocate arrays in C++
- What is the best way to use a HashMap in C++?
- What is the best way to use a HashMap in C++?
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Sleep for milliseconds
- How to convert string to char array in C++?
- How can I convert a std::string to int?
- Easiest way to convert int to string in C++
- What is the difference between float and double?
- Why is “using namespace std;” considered bad practice?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- outputting ascii table in C++
- What is a lambda expression in C++11?
- Vector of Vectors to create matrix
- How to throw a C++ exception
- std::string to char*
- How to generate a random number in C++?
- pinpointing “conditional jump or move depends on uninitialized value(s)” valgrind message
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- How do I find the length of an array?
- Sleep for milliseconds
- How to convert string to char array in C++?
- C++ — expected primary-expression before ‘ ‘
- Using getline() with file input in C++
- What is the effect of extern “C” in C++?
- C++ Cout & Cin & System “Ambiguous” [closed]
- ld: symbol(s) not found for architecture x86_64 error