In GCC or g++, when two classes need to refer to each other:
If a pointer to another class is declared in a.h file of one class, the class keyword can be used to declare the pointer first, instead of including the header file.
However, if an object defining a class or a specific member of a class is involved, the header file for that class must be included and declared without the class keyword.
Otherwise, a compilation error as shown in the title will occur!
If we want to define A pointer to class B in the header file of class A, and we want to define A pointer to class A in class B, then we can use class B in class A
Declare, without needing to contain a header file of class B,
But when we need to call A method of class B, we need to include its header file, which can then be included in the.cpP file of class A
Header file #include < B.h> , and the same is true in class B
If a pointer to another class is declared in a.h file of one class, the class keyword can be used to declare the pointer first, instead of including the header file.
However, if an object defining a class or a specific member of a class is involved, the header file for that class must be included and declared without the class keyword.
Otherwise, a compilation error as shown in the title will occur!
If we want to define A pointer to class B in the header file of class A, and we want to define A pointer to class A in class B, then we can use class B in class A
Declare, without needing to contain a header file of class B,
But when we need to call A method of class B, we need to include its header file, which can then be included in the.cpP file of class A
Header file #include < B.h> , and the same is true in class B
Read More:
- Error tips:array type has incomplete element type
- array type has an incomplete element type
- variable ‘std:ofstream’ has initializer but incomplete type
- After introducing sass into Vue project, start to report error typeerror [err]_ INVALID_ ARG_ Type]: the “path” argument must be of type string
- error: invalid use of non-static member function
- Use yum to prompt Error: rpmdb open failed
- Cause: java.sql.SQLException: invalid column type: 1111 Error [How to Fix]
- [Solved] Logon failed, use ctrl+c to cancel basic credential prompt. unable to access
- nvalid default value for prop “params“: Props with type Object/Array must use a factory function to
- Invalid use of element UI icon by vite
- Use mujoco = = 0.5.7 to run the code and report error: invalid activation key
- Command prompt window prompt system error 5, access denied?
- To solve the problem of C # calling excel interface error, prompt: the COM object of Microsoft. Office. Interop. Excel. Applicationclass is forcibly converted to the interface type “Microsoft. Offi”
- New user’s shell, delete prompt ^ H, up and down prompt ^ A ^ B, tab key is useless
- Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
- How to use scanner to accept char type characters in Java
- [Vue warn]: Invalid prop: type check failed for prop “disabled“
- Incomplete and “the Jupiter” distribution was not found
- Zend studio HTML error prompt close, PHP “error prompt” open and close the correct way
- The @ Autowired annotation in springboot is invalid in ordinary classes. How to solve and use the null pointer exception java.lang.nullpointerexception