So I have a class included in another class that keeps throwing a compile error of the form "error: 'ProblemClass' has not been declared. The files are set up thusly:
#ifndef PROBLEMCLASS_H #define PROBLEMCLASS_H #include <iostream> #include <cmath> class ProblemClass { public: virtual void Init() = 0; }; #endif
and the class where the error occurs looks like this:
#ifndef ACLASS_H #define ACLASS_H #include "problemclass.h" class AClass : public Base { public: void DoSomething(ProblemClass* problem); }; #endif
The compile error occurs at void Dosomething();
I'm aware the code here isn't enough to solve the problem. I've been unable to create a minimal example that can reproduce it. So my question is much more general; what sort of things might cause this? Is there anything in particular I should look for, or some line of enquiry I should be following to track it down?
This code compiles fine in an almost identical version of the project.
Help of any sort would be greatly appreciated, no matter how vague. I'm using codeblocks 10.05 with mingw4.4.1 in win 7 64 bit.
You seem to be saying that the code you are showing doesn't actually produce the compiler error that you are having a problem with. So we can only guess. Here are some possibilities:
problemclass.h
from the file where you are using ProblemClass
.ProblemClass
either in its own header file or in the place where you are using it. This can be hard to spot if it is a capitalization error such as writing Problemclass
or problemClass
instead of ProblemClass
.#defines
from one header file to another and then forgot to change the defined names. Then only the first of those two included header files would take effect.ProblemClass
in a namespace A
, in which case you must refer to ProblemClass
as A::ProblemClass
if you are referring to it from outside the namespace A
.ProblemClass
a macro that only gets defined after you include problemclass.h
, in which case what you see as ProblemClass
gets replaced by something else by the macro preprocessor.ProblemClass
in a header file other than problemclass.h
and then problemclass.h
actually defines something else.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With