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
- How do I find the length of an array?
- C++ — expected primary-expression before ‘ ‘
- Using getline() with file input in C++
- g++ ld: symbol(s) not found for architecture x86_64
- How do I iterate over the words of a string?
- C++ Vector of pointers
- error: lvalue required as unary & operand
- What is use of c_str function In c++
- Is there a decent wait function in C++?
- invalid use of non-static member function
- Cannot open include file: ‘stdio.h’ – Visual Studio Community 2017 – C++ Error
- srand(time(0)) and random number generation
- How to convert integer to double implicitly?
- How do I tokenize a string in C++?
- Reverse Contents in Array
- Why would we call cin.clear() and cin.ignore() after reading input?
- Should I learn C before learning C++?
- Comparison with string literal results in unspecified behaviour?
- What are the most widely used C++ vector/matrix math/linear algebra libraries, and their cost and benefit tradeoffs?
- Insert object at index of vector c++
- Read whole ASCII file into C++ std::string
- Reading getline from cin into a stringstream (C++)
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- Call to implicitly deleted copy constructor in LLVM
- What is the use of intptr_t?
- to_string not declared in scope
- C++ Initializing a Global Array
- How to convert an ASCII char to its ASCII int value?
- Call to non-static member function without an object argument compiler error
- How can I assign an array from an initializer list?
- “vector” was not declared in this scope
- Converting string to ASCII
- got “cannot appear in a constant-expression” when using template
- C++ ostream and ofstream conversions
- C++ discards qualifiers
- error C2065: ‘cout’ : undeclared identifier
- How to get the MD5 hash of a file in C++?
- C++ Error: Expected a type specifier
- Where to declare/define class scope constants in C++?
- Friend methods error
- Does WPF Work with C++?
- Multiple inputs on one line
- Compiler error C4430: missing type specifier – int assumed [duplicate]
- ‘&’ : illegal operation on bound member function expression [duplicate]
- Multiple definitions of “Main”
- Getting the error floating point exception: 8