This is a circular dependency issue. For declaring a pointer to some class, the definition of the class is not needed; i.e. the type doesn’t have to be a complete type. So you don’t need to include A.h
in B.h
, forward declaration is enough. Such as:
//B.h class A; // change the include of A.h to forward declaration class B { A* a; };
Related Posts:
- Resolve build errors due to circular dependency amongst classes
- Error “Unterminated conditional directive” in cross-referencing headers
- error: expected unqualified-id error: Meaning and fix? [duplicate]
- c++ compile error: ISO C++ forbids comparison between pointer and integer
- error: redefinition of class
- C++ Error: No match for ‘operator=’
- Identifier not found error on function call
- What is an ‘undeclared identifier’ error and how do I fix it?
- Identifier not found error on function call
- What is an ‘undeclared identifier’ error and how do I fix it?
- C ++ error: a expected initializer before [function name]
- invalid new-expression of abstract class type
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- “Symbol(s) not found for architecture x86_64” on QtCreator project
- error: redefinition of class
- C++ error: “Array must be initialized with a brace enclosed initializer”
- error: expected primary-expression before ‘)’ token (C)
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- C++ #include guards
- C++ #include guards
- class not declared in scope – even though .h was included
- C++ error: definition of implicitly-declared
- Already defined in .obj – no double inclusions
- cc1plus: error: unrecognized command line option “-std=c++11” with g++
- extra qualification error in C++
- Cannot open output file, permission denied
- Random not declared in scope
- Call to non-static member function without an object argument compiler error
- What is the difference between a .cpp file and a .h file?
- multiple definitions error in c++ and solution to solve this issue
- Stray ‘\342’ in C++ program
- System not declared in scope?
- Error in assignment of member in read-only object
- Call of overloaded function is ambiguous
- error: ISO C++ forbids in-class initialization of non-const static member
- Error: expression cannot be used as a function?
- cmath vs math.h (And similar c-prefixed vs .h extension headers)
- Unexpected end of file error
- virtual memory exhausted: Cannot allocate memory
- Eclipse CDT: Symbol ‘cout’ could not be resolved
- How many spaces for tab character(\t)?
- How do I build a graphical user interface in C++? [closed]
- What are the differences between a pointer variable and a reference variable in C++?
- outputting ascii table in C++
- What is the effect of extern “C” in C++?
- finding dll for “The specified module could not be found”
- no matching function for call to ‘ ‘
- Read file line by line using ifstream in C++
- Convert an int to ASCII character
- When should I write the keyword ‘inline’ for a function/method?
- When does a process get SIGABRT (signal 6)?
- Logical XOR operator in C++?
- C++ – Decimal to binary converting
- Alternative to itoa() for converting integer to string C++?
- 1e-9 or -1e9, which one is correct?
- “&” meaning after variable type
- How can I create objects while adding them into a vector?
- What is the printf format specifier for bool?
- libpng warning: iCCP: known incorrect sRGB profile
- In CLion, header only library: file “does not belong to any project target, code insight features might not work properly”
- Is a function definition not allowed here before a ‘{‘ token?
- terminate called after throwing an instance of ‘std::out_of_range’
- What does “missing template argument” mean?
- How do I call the class’s destructor?
- Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)
- Defining a struct in flex error C++
- C++ Postfix calculator using stacks
- LNK1168: cannot open debug\file.exe for writing
- Can I output a one channel image acquired from camera into a winAppi window?
- Difference in make_shared and normal shared_ptr in C++
- Printing an array in C++?
- error: “initializer expression list treated as compound expression”
- The compiler is complaining about my default parameters?
- read word by word from file in C++
- How to replace all occurrences of a character in string?
- Deleting an object in C++
- Appending a vector to a vector
- C++ Expression must have pointer-to-object type
- Multi-character constant warnings
- Error: vector does not name a type
- How to convert ASCII value into char in C++?
- How to alphabetically sort strings?
- Function definition not found for a function declared inside unnamed namespace – how to resolve? (Visual Studio 2015)
- How do I check if a C++ std::string starts with a certain string, and convert a substring to an int?
- Iterator Loop vs index loop
- OpenCV Error: Assertion failed (size.width>0 && size.height>0) simple code
- operator << must take exactly one argument
- Is there a C++ equivalent to getcwd?
- expected primary-expression before ‘]’ token
- What is the return type of sizeof operator?
- C++ 2d char array to string
- Error: member function may not be declared outside of its class.
- What is the size of sizeof(vector)? C++
- C++ – Print Out Objects From Set
- Why virtual & static keywords aren’t allowed outside class declaration?
- C++ Signed/unsigned mismatch
- What does _T stands for in a CString
- mysql.h file can’t be found
- Getting an error “fopen’: This function or variable may be unsafe.” when compling [duplicate]
- The tilde operator in C