Thread: Class read as variable, default-type int? Say what?!

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    58

    Class read as variable, default-type int? Say what?!

    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.

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    you need to tell it what ApplicationManager is before you can make one
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    I'm a little confused about what you are instructing me to do. ApplicationManager is the Class, so the ApplicationManager itself is an object. "manager" is the variable name, while ApplicationManager is the variable type.

    The Application Manager class is already defined in "ApplicationManager.h", which was provided above.

    Could you please elaborate on your explanation?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by arcaine01 View Post
    I'm a little confused about what you are instructing me to do. ApplicationManager is the Class, so the ApplicationManager itself is an object. "manager" is the variable name, while ApplicationManager is the variable type.

    The Application Manager class is already defined in "ApplicationManager.h", which was provided above.

    Could you please elaborate on your explanation?
    Had you defined your application manager class correctly, you wouldn't be getting this error. Therefore you aren't doing so. Perhaps there's something gone wrong in application.h?

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    Quote Originally Posted by tabstop View Post
    Had you defined your application manager class correctly, you wouldn't be getting this error. Therefore you aren't doing so. Perhaps there's something gone wrong in application.h?

    Well...here is the application class header.
    Code:
    #ifndef _APP_H_
    #define _APP_H_
    #include "d3dgraphics.h"
    class Application
    {
    public:
    	Application(void);
    	~Application(void);
    
    	virtual void LoadContent();
    	virtual void UnloadContent();
    
    	void DrawStart(GraphicDevice);
    	virtual void Draw(void);
    	void DrawEnd(GraphicDevice);
    	
    	virtual void Update();
    
    	void SetFrameRate(float value);
    	float FrameRate(void) {return _FrameRate;}
    private:
    	float _FrameRate;
    };
    #endif

    Here is D3DGraphics.h file
    Code:
    #ifndef _GRAPHIC_DEVICE_H_
    #define _GRAPHIC_DEVICE_H_
    #include <windows.h>
    #include <d3d9.h>
    #include "Window.h"
    #pragma comment (lib, "d3d9.lib")
    class GraphicDevice
    {
    public:
    	GraphicDevice(Window app);
    	void Dispose();
    	void Draw();
    	D3DPRESENT_PARAMETERS DeviceInfo() {return _DeviceInfo;}
    	LPDIRECT3D9 Interface() {return _Interface;}
    	LPDIRECT3DDEVICE9 Device() {return _Device;}
    private:
    	D3DPRESENT_PARAMETERS _DeviceInfo;
    	LPDIRECT3D9 _Interface;
    	LPDIRECT3DDEVICE9 _Device;
    };
    #endif


    Here is the window.h file
    Code:
    #ifndef _WINDOW_H_
    #define _WINDOW_H_
    #include <windows.h>
    #include <windowsx.h>
    #include "Point.h"
    class Window
    {
    public:
    	Window(HINSTANCE currentHandle, int ShowCMD, bool fullscreen);
    	Window(HINSTANCE currentHandle, int ShowCMD, int width, int height, bool fullscreen);
    	Window(HINSTANCE currentHandle, int ShowCMD, int width, int height, int x, int y, bool fullscreen);
    	Window(HINSTANCE currentHandle, int ShowCMD, Point size, Point location, bool fullscreen);
    	~Window(void);
    	void Initialize(void);
    	int State(void);
    	int Width() {return _Width;}
    	int Height() {return _Height;}
    	int X() {return _X;}
    	int Y() {return _Y;}
    	bool isFullscreen() {return Fullscreen;}
    	HWND &Handle() {return WindowHandle;}
    private:
    	WNDCLASSEX WindowObject;
    	HINSTANCE Instance;
    	HWND WindowHandle;
    	int _Width, _Height, _X, _Y;
    	bool Fullscreen;
    protected:
    };
    #endif



    All classes appear to be declared and define properly to me. Do you see any problems?

  6. #6
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    game.h creates an ApplicationManager object before you define the ApplicationManager class
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The problem is you have a circular dependency. game.h includes applicationmanager.h, and applicationmanager.h inclues game.h.

    You need to forward declare ApplicationManager in game.h and remove the inclusion of applicationmanager.h. Then you can include applicationmanager.h in game.cpp. With this change, you will need to declare management as a ApplicationManager pointer, and then instantiate it in game.cpp.

    In other words:
    Code:
    #ifndef _GAME_H_
    #define _GAME_H_
    #include "application.h"
    //#include "applicationmanager.h" note that this is commented out now
    
    class ApplicationManager;
    
    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
    Of course I don't see any reason why applicationmanager.h includes game.h at all. If you can, just remove that include and then you don't need to make the above changes.

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    58
    wow lol...did not see game.h in the appmanager....Thank you VERY much for pointing that out!

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    In your applicationmanager.h you have these two includes:
    Code:
    #include "game.h"
    #include "application.h"
    Which don't appear to be needed in the header, so you can get rid of those.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  4. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM