"Does not name a type" error, but class pointer already has forward declaration?

c++, compiler-errors, forward-declaration

Solution

In the end, I am not sure I understand completely why the error occurred, but this is what I did to resolve it, and some other related information. Maybe this will help others that come across this question.

- For each header file in my project

- For each `#include "..."` in the header

- If there are no references to the class in the `#include`, remove it.

- If there are only pointers to the class defined in the `#include`, then replace it with a `class ...` forward declaration.

- If there is a member instance of the class defined in `#include` and it makes sense to use a pointer and allocate the member on the heap, then change the member to a pointer, and replace the `#include` with a `class ....` forward declaration.

- Go through my `Globals.h` and move anything that can be moved out of it to more localized and specific header files.

- Specifically, remove an `enum` that was defined is `Globals.h`, and place it in a more localized header file.

After doing all this I was able to make the error go away. Strangely enough, the `enum` in `Globals.h` seemed to be a catalyst for the error. Whenever I removed it from `Globals.h`, the error would go away. I don't see how this `enum` could cause the error, so I think it indirectly led to the error somehow. I still wasn't able to figure out exactly how or why, but it has helped me for this guideline when coding in C++:

Don't put anything in a header file unless it needs to be there. Don't place anything in a `Globals.h` that can be placed in a more localized file. Basically, do all you can to reduce the amount of code that is included through the `#include` directives.

Problem

I am getting this compiler error ``` error: 'RawLog' does not name a type ``` Here is the relevant code: ``` //DataAudit.h #ifndef DATAAUDIT_H #define DATAAUDIT_H class RawLog; class DataAudit { ... private: RawLog* _createNewRawLog(); // This is the line indicated with the error }; #endif // DATAAUDIT_H ``` Usually a forward declaration resolves this kind of error. This answer indicates that a circular header inclusion may cause this. But doesn't the use of the `#ifndef` and `#define` statements prevent circular header inclusion? Is there another reason I might see this error? What are some avenues of approach I could use to further deduce the nature of this error? Update: This is rather odd. I have a `Globals.h` file, and if I define a new `enum` in `Globals.h`, the error appears. Then if I comment out the `enum`, the error goes away. This leads me to think that the circular dependency has existed for a while, and adding the `enum` somehow re-orders the compilation units, thus exposing the dependency that wasn't there before?

Original source