views:

47

answers:

2

Hi to all,

I'm writing a project in Visual C++ 2010 Express edition. Everything was fine before i tried to add new source file in the project. Then when i tried to include one of the header files the compiler said that the class declared in this header is not found in other source file which includes the same header file.

This is output from build. I've added #pragma message in each header file to see when it is included.

1>------ Build started: Project: OSGF, Configuration: Debug Win32 ------
1>  OSGFComponentManager.cpp
1>      OSGFComponentManager.h included
1>      OSGFComponent.h included
1>      Game.h included
1>      GameTimer.h Included
1>      ScreenText.h included
1>      OSGFDrawableComponent.h icluded
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(7): error C2504: 'OSGFComponent' : base class undefined
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(10): error C2061: syntax error : identifier 'Game'
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(10): error C2065: 'game' : undeclared identifier
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(12): error C2614: 'OSGFDrawableComponent' : illegal member initialization: 'OSGFComponent' is not a base or member
1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(16): error C2027: use of undefined type 'OSGFComponent'
1>          d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(4) : see declaration of 'OSGFComponent'
1>d:\myprograms\osgf\osgf\screentext.h(11): error C2061: syntax error : identifier 'Game'
1>  Generating Code...
1>  Compiling...
1>  Main.cpp
1>      Test.h included
1>      Game.h included
1>      GameTimer.h Included
1>      ScreenText.h included
1>      OSGFDrawableComponent.h icluded
1>      OSGFComponent.h included
1>  Generating Code...
1>  Compiling...
1>  Test.cpp
1>      Test.h included
1>      Game.h included
1>      GameTimer.h Included
1>      ScreenText.h included
1>      OSGFDrawableComponent.h icluded
1>      OSGFComponent.h included
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========  
A: 

I guess the header containing the definition of OSGFComponent must be included eigther in osgfdrawablecomponent.h or OSGFComponentManager.cpp in before including osgfdrawablecomponent.h

frag
It is included.
Dani
A: 

Have you included OSGFComponent.h and Game.h in the osgfdrawablecomponent.h header file ?

Kiril Kirov
Yes. The code is working properly when I remove the #include "OSGFComponentManager.h" from OSGFComponentManager.cpp.
Dani
How it's working properly, as your declarations are in the header file (.h ) ? It's not possible, if you have only implementation in the cpp file. Or, OSGFComponentManager.h is included in some other header file, that's included in OSGFComponentManager.cpp ? Also, are you using #ifdef-#define-#endif macros ?
Kiril Kirov
I'd suggest you to post your code here, if it's not very long, because all we can do is just to shoot in the dark, without seeing you're source.
Kiril Kirov
Here is the source. http://bitbucket.org/dshaprin/osgf/src/tip/OSGF/ I also commented all method definitions in the OSGFComponentManager.cpp And I'm not using this class yet.
Dani
Include "game.h" in "ScreenText.h" and in osgfcomponent.h, also uncomment all function bodies in "OSGFComponentManager.cpp" or you'll get a linking error. Also, there's no need from forward declarations (as class Game; when you'hv included the header Game.h). Delete this class OSGFComponent* dummy; in the osgfdrawablecomponent.h. Compile this and give me the new errors :)
Kiril Kirov
I've pushed the new code. >d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(6): error C2504: 'OSGFComponent' : base class undefined1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(9): error C2061: syntax error : identifier 'Game'1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(9): error C2065: 'game' : undeclared identifier1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(11): error C2614: 'OSGFDrawableComponent' : illegal member initialization: 'OSGFComponent' is not a base or member1>d:\myprograms\osgf\osgf\osgfdrawablecomponent.h(15): error C2653: 'OSGFComponent' : is not a class or n
Dani
I need to see the errors, to be able to help anyway. Or they're the same :?
Kiril Kirov
They're the same.
Dani
You haven't removed the forward declarations. Try without them. Also having Game in OSGFComponent is kinda dangerous. This way, the object 'game', you're passing to the constructor must be created with operator new.. use Game mGame; instead, just in case.
Kiril Kirov
When i remove the forward declaration in OSGFComponent.h The compiler doesn't find Game class in this file and the old errors are still there. About the reference, I want to have one object for all components, not copy in every one of them.
Dani
OK for the reference, sorry (: About the class Game - it's not possible. If the compiler does not find class Game, even when the Game.h is included, then the problem is in the Game.h file. Sorry, but I cannot compile it, as I use Linux and you're using some 3rd-party Windows libs, that I don't have in Linux.
Kiril Kirov
Argh, you've a problem with this includes. Redesign them, because you're including Game.h in OSGFComponent.h, Game.h includes ScreenText.h, ScrenText.h includes osgfdrawablecomponent.h, which includes osgfcomponent.h, which again includes Game.h and so on. Definitely redesign is needed. Try to export the common parts into a different header, or use forward declarations somewhere. That's you're problem - this circus.
Kiril Kirov
For example, you could try to remove #include "osgfdrawablecomponent.h" from ScreenText.h and use only forward declaration (as you're not actually using it in the cpp file), or try to remove #include "Game.h" from OSGFComponent.h and use only forward declaration. Something like this. Try them. Also, really redesign your things, this kind of includes are really confusing and unpleasant.
Kiril Kirov
Thanks a lot. I removed #include "Game.h" and everything works fine now.
Dani
I'm glad that I helped (:
Kiril Kirov