Sign in to follow this  
BaneTrapper

Creating global static object

Recommended Posts

I have problem making static global class object
i try to define it in "Define.h"
Any one can fix this error?

[CODE]
/* Define.h */
#ifndef DEFINE_H_INCLUDED
#define DEFINE_H_INCLUDED
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define SCREEN_BPP 32

#include "App.h"
static App obj_App; /* Error is here " 'App' does not name type" why... i just included App.h above which posses App as class */

#endif // DEFINE_H_INCLUDED


/* App.h */
#ifndef APP_H_INCLUDED
#define APP_H_INCLUDED
#include <SDL.h>
#include "Define.h"
class App
{
public:
App(); /*aaaaaaaaaaaaaaaaa*/
Uint8 AppInit(); /* Main stuff to game */
void AppExit(); /*aaaaaaaaaaaaaaaaa*/
private:
SDL_Surface *surf_Screen; /*aaaaaaaaaaaaaaaaa*/
public: /* surf_Screen */
SDL_Surface** GETP_surf_Screen(); /*aaaaaaaaaaaaaaaaa*/
public:
Uint8 AppStart(); /*aaaaaaaaaaaaaaaaa*/
void GameLoop(); /*aaaaaaaaaaaaaaaaa*/
private:
bool is_On, /*aaaaaaaaaaaaaaaaa*/
is_Game, /* bools for game handle */
is_Menu;
public:
bool* GETP_is_On();
bool* GETP_is_Game(); /* Bool handle */
bool* GETP_is_Menu(); /*aaaaaaaaaaaaaaaaa*/
};
#endif // APP_H_INCLUDED


/* Main.cpp */
#include "Define.h"
int main(int argc, char* args[])
{
return obj_App.AppStart();
}
[/CODE]

Share this post


Link to post
Share on other sites
define.h is including app.h, and app.h is including define.h. Both headers cannot be included before each other so you have an infinite recursion. The include guard is stopping that recursion, but in the end, one header will he included before the other and will be missing the content of the other file. You have circular dependencies between the include files.

What you have is going to cause a problem anyway even if the circular dependency was removed. You're declaring an instance of App in the header file, which will leave you with a separate instance of the App in each source file app.h is included. Instead of defining it as static, declare it as extern instead and then define it in a single source file. A good place to declare it is in app.h instead, since that's where the App class is defined.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this