Jump to content
  • Advertisement
Sign in to follow this  

Creating global static object

This topic is 2250 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

/* Define.h */
#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 */


/* App.h */
#include <SDL.h>
#include "Define.h"
class App
App(); /*aaaaaaaaaaaaaaaaa*/
Uint8 AppInit(); /* Main stuff to game */
void AppExit(); /*aaaaaaaaaaaaaaaaa*/
SDL_Surface *surf_Screen; /*aaaaaaaaaaaaaaaaa*/
public: /* surf_Screen */
SDL_Surface** GETP_surf_Screen(); /*aaaaaaaaaaaaaaaaa*/
Uint8 AppStart(); /*aaaaaaaaaaaaaaaaa*/
void GameLoop(); /*aaaaaaaaaaaaaaaaa*/
bool is_On, /*aaaaaaaaaaaaaaaaa*/
is_Game, /* bools for game handle */
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();

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!