Static class obj

Hello.
Problem with static class object.
1
2
3
4
5
6
7
8
9
10
11
12
13
class Main
{
   public:
      static Main Maincontrol;
   
      bool Running;  "and i set Running = true in constructor"
}

class Event
{
   public:
      void ac();
}


when im calling a function in class Event:
 
Main::Maincontrol.Running = false

it dosent set Running to false!.
but it compiles good.


it dosent set Running to false!.

Yes, it does. What makes you think otherwise?
If Maincontrol is an object of class main try just Maincontrol.Running=false.
Replay to Ather
Well somhow it dosent.
bool is public, weird thing is i got a call below it like this
1
2
   Main::MainControl.Running = false;
   Main::MainControl.SurfScreen = SurfLoad


the surf is changed but the Running is still true...
ive checked for error but nothing wrong its clean code...
i tryed with making Main ObjectMain; in the function and using it
 
ObjectMain.Running = false

still when i check it its true so....
still when i check it its true so....

And where/how do you do that?
i got 24 file code... ^^
i got pre one bifore i made the Event class..."has 22"
i tried to retipe it, error is the same for sake of someone looking for problem il post it when i figure it out but ... until then its fixed

EDIT: progres has been made'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef MAIN_H_INCLUDED
    #define MAIN_H_INCLUDED
#include <SDL.h>

#include "Loadup.h"
#include "Cleanup.h"
#include "Render.h"
#include "Event.h"

class Main
{
    public:
        static Main MainControl;
        bool Running;
        SDL_Surface* SurfScreen;

        Main();
        int Startup();
        SDL_Surface* ReturnScreen();



};

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef EVENT_H_INCLUDED
    #define EVENT_H_INCLUDED

#include "Main.h"

class Event
{
    public:
        static Event EventControl;
        void KeyInput(SDL_Event* Events);
    private:
        Main StaObj;
};

#endif 

in class Event " Main StaObj " compiler returns: error: 'Main' does not name a type
??? ani how to make a class object ?! "In other class i do same include and it works" >:!
Last edited on
Topic archived. No new replies allowed.