Strange problem with include file

Aug 19, 2010 at 10:46pm
Hello.
I am working on a project in Visual Studio 2008. It has over 50 classes divided in folders and subfolders. Everything compiled nicely except two lines:

RandomTimedFlowElement.cpp
d:\c++_projects\projekat2010\pr2010\projekat_2010_1.0\concepts\abstract concepts\randomtimedflowelement.cpp(22) : error C2653: 'Event' : is not a class or namespace name
d:\c++_projects\projekat2010\pr2010\projekat_2010_1.0\concepts\abstract concepts\randomtimedflowelement.cpp(22) : error C3861: 'create': identifier not found

Event class is in Event.h and create is static function in Event class.
This is strange because I included this class regularly and this cpp file doesn't see it. They are not in the same folder but when they are everything is OK.
So what should I do because I can't move .h file? It is needed in some other class also. I set include paths but the problem remains.
Why compiler doesn't just say: Event.h cannot open such file... but gives me these errors.
Please help.
Aug 20, 2010 at 2:05am
Are you doing <event.h> or "event.h"?

If you're doing <event.h>, the compiler will look for event.h in the current directory, and if it doesn't find it, it will start looking in other directories (like standard lib directories, etc). It's possible it's finding a totally unrelated file with the same name and including that instead.


If you're doing "event.h", the compiler should certainly be giving you an error if the file doesn't exist in the directory.


If the directory is in another path, you'll have to qualify the pathname. remember that .. goes one directory up. so, let's say the cpp file is in directory "myproject/a/source.cpp" and event.h is in "myproject/b/event.h". Your include would look like this:

 
#include "../b/event.h" 


If you find yourself with excessively long #include lines and lots of "..", it's a sign your directory system is overcomplicated.

EDIT: also, use /, not \\ for the directory marker. Even if you're on Windows. \\ should never be used in C++ as a directory marker.
Last edited on Aug 20, 2010 at 2:07am
Aug 20, 2010 at 2:47am
Thank you for your reply but I already tried both "Event.h" and <Event.h> but nothing changed.
And, like I said, compiler doesn't raise error that he can't open include file just that he can't find the class...
There is another .cpp which is using Event.h as include and it works normally. But this cpp file is in the same folder as the Event.h. So I moved include to the folder of the first cpp and the same thing happens only with other cpp. My guess is that something is wrong with my search paths. I set them all like absolute paths to find the solution but I achieved nothing... The error is the same.
Nikola
Aug 20, 2010 at 9:33am
Hello,

Yes, it is overcomplicated with those folders and subfolders.
50 is not that much to make a descending list of .h files
containing these classes along with paths, though it sounds hard to do.
In reward you will get clear classes view then include it
in a header file under a name of your choice.
Otherwise the problem may evaluate to even harsher state of the system.
Aug 20, 2010 at 2:17pm
Thank you for your reply but I already tried both "Event.h" and <Event.h> but nothing changed.


Well you want "Event.h" (or really, you want "../b/Event.h" or whatever outlines the correct path)

And, like I said, compiler doesn't raise error that he can't open include file just that he can't find the class


I'm a little flabbergasted by this. It really should be. What compiler are you using?

My guess is that something is wrong with my search paths


Search paths should not be involved. They only get involved if you're doing <Event.h>, which you shouldn't be.

I set them all like absolute paths to find the solution but I achieved nothing


Well you don't want absolute paths, but you do want paths relative to the current directory.

How about this:

- what path is event.h in?
- what path is the problem cpp file in?

If I know those 2 things I can show you the proper #include line
Aug 21, 2010 at 7:05pm
I finally solved it. I deleted all include paths and entered knew ones but this time used relative paths like Disch said. First entered the paths to folders and after these to subfolders and project compiled nicely. Don't know why. Anyway I'm happy. Thanks everyone.
Nikola
Topic archived. No new replies allowed.