C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-10-2009, 03:44 PM   #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.
arcaine01 is offline   Reply With Quote
Old 07-10-2009, 03:48 PM   #2
Banned
 
ಠ_ಠ's Avatar
 
Join Date: Mar 2009
Posts: 533
you need to tell it what ApplicationManager is before you can make one
__________________
╔╗╔══╦╗
║║║╔╗║║
║╚╣╚╝║╚╗
╚═╩══╩═╝
ಠ_ಠ is offline   Reply With Quote
Old 07-10-2009, 03:55 PM   #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?
arcaine01 is offline   Reply With Quote
Old 07-10-2009, 03:57 PM   #4
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
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?
tabstop is offline   Reply With Quote
Old 07-10-2009, 04:10 PM   #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?
arcaine01 is offline   Reply With Quote
Old 07-10-2009, 04:17 PM   #6
Banned
 
ಠ_ಠ's Avatar
 
Join Date: Mar 2009
Posts: 533
game.h creates an ApplicationManager object before you define the ApplicationManager class
__________________
╔╗╔══╦╗
║║║╔╗║║
║╚╣╚╝║╚╗
╚═╩══╩═╝
ಠ_ಠ is offline   Reply With Quote
Old 07-10-2009, 04:23 PM   #7
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 2,845
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.
bithub is offline   Reply With Quote
Old 07-10-2009, 04:33 PM   #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!
arcaine01 is offline   Reply With Quote
Old 07-10-2009, 05:34 PM   #9
and the hat of sweating
 
Join Date: Aug 2007
Location: Toronto, ON
Posts: 3,119
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
cpjust is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code review Elysia C++ Programming 71 05-13-2008 09:42 PM
failure to import external C libraries in C++ project nocturna_gr C++ Programming 3 12-02-2007 03:49 PM
30something GSOH seeks help with the basics of a minor programme promsan C Programming 3 05-13-2007 08:55 AM
Working with random like dice SebastionV3 C++ Programming 10 05-26-2006 09:16 PM
Warnings, warnings, warnings? spentdome C Programming 25 05-27-2002 06:49 PM


All times are GMT -6. The time now is 07:20 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22