Results 1 to 3 of 3

Thread: Accessing the global application instance

  1. #1

    Default Accessing the global application instance

    Is there a proper way to do this, you know, from outside my Application.cpp and Application.h? Should it even be done?

    I have an input event handler class which should work by translating the events into calls to application functions/signals (which either issue a command to game logic or adjust some application parameter). I thought it would be as simple as marking the application instance as static and then #including Application.h.

    But it seems that the instance which the input handler sees is NOT the global one I want -- from what the debugger and my own investigations tell me, it is a new instance whose members have yet to be initialized. I've tried redeclaring the global instance as extern, and it hasn't helped. What do I do?

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Well, I'm not totally sure if this is what you mean, but I do access my "main instance" everywhere, should be fine.

    In my main.cpp:

    Code:
    App MyApp; //declare the main app global
    App * GetApp(){return &MyApp;}
    In my main.h:

    Code:
    class App : public CL_ClanApplication
    {
    public:
        App();
        virtual ~App();
    ..blah blah a bunch of junk specific to the app...
    };
    
    extern App MyApp;
    App * GetApp();
    And then I use GetApp()->SomeFunction() everytime I need something from outside the MyApp class.
    Seth A. Robinson
    Robinson Technologies

  3. #3

    Default

    It turns out that, yes, my improper use of extern was the problem. Declare the global instance in Application.cpp, and again as extern in Application.h, so all a class need do is #include Application.h.

Similar Threads

  1. Application crashing before it fuly starts up?
    By kaminarukuzu in forum Novashell Game Creation System
    Replies: 9
    Last Post: 12-30-2006, 06:24 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •