tags:

views:

147

answers:

3

So, I have two classes...Very basic in structure. I try to import one into the other, and declare a new object of that class type...however, it seems to read the class name as the name of a variable?!

The header class provided below will not read the "ApplicationManager" class properly. Code:

####ifndef _GAME_H_  
####define _GAME_H_  
####include "application.h"  
####include "applicationmanager.h"  
class Game : public Application  
{  
public:  
    Game();  
    ~Game();  
    void LoadContent() override;  
    void UnloadContent() override;  
    void Draw() override;  
private:  
    //int ApplicationManager; //WHY DOES THIS COMPILE??!  
    ApplicationManager management; //This DOES NOT WORK?  
};  
####endif

Here is the header for the "ApplicationManager" class. Code:

####ifndef _APPMANAGER_H_  
####define _APPMANAGER_H_  
####include "game.h"  
####include "application.h"  
class ApplicationManager  
{  
public:  
    ApplicationManager(void);  
    ~ApplicationManager(void);  
private:  
};  
####endif

The error that occurs, tells me that I need a ";" before "management", and that "ApplicationManager" is missing a type specifier, so it is assumed to be default-type int.

...any ideas why it won't compile properly? Can someone else try this and report the results? I copied the code, and pasted it in a different solution, to see if something became corrupted....it still didn't work.

+8  A: 

You have a cyclic reference. When game.h is included from applicationmanager.h, the ApplicationManager class has not yet been read by the compiler.

To fix, remove the line

#include "game.h"

from applicationmanager.h.

Paolo Capriotti
+2  A: 

Why do you have circular dependency between Game.h and AppicationManager.h?

Aside from that, I'd say check your header guard (#ifdef _*_H) in Application.h. A fairly often occurence in C++, when copy/pasting code or copying files, is to forget to change the header guard define name for a new class, so you end up with two different headers guarded by the same define. In which case, if both are included into some other file, only the first will actually be expanded into anything useful.

Pavel Minaev
+1  A: 

THe error message is some what misleading. It basically says "For some reason (probably an error in the referenced type) I cannot recognize the type you're using (in you case ApplicationManager)". If you need ApplicationManager to know about Game make a pure virtual base class (interface in other terms) and have Game inherit from that (with out extending the interface) and have ApplicationManager include the base class header file

Rune FS