Page 1 of 1

Static variables in classes not allowed

Posted: Tue Jun 01, 2010 9:59 am
by Karlosoft
Hi! I have a new problem today, the static vars. This is a sample of class that uses them

Code: Select all

class frame{
      private:
              [color=#804000][b]static uint32 nextId;[/b][/color]
              uint32 id;
              uint8 refreshed;
              frame* parent;

              frame* children[128];

              uint8 status;               //Visible enabled etc etc
              
              uint16 width, height, top, left;
              
              uint32 zindex;
              
              
      public:
             static void init_frame();
             frame(frame* a_p, uint16 a_w, uint16 a_h, uint16 a_t, uint16 a_l, uint32 a_z);
             frame();
             void refresh();
             void* draw(frame*);      //TO draw
      
      }nullFrame;
The problem is the red line. The linker isn't able to manage it so it tries to link it in every section. How to solve this problem? Now I'm using it out from the class but it makes the code less readable :)

Re: Static variables in classes not allowed

Posted: Tue Jun 01, 2010 10:52 am
by Karlosoft
Thank you! It works :)

Re: Static variables in classes not allowed

Posted: Tue Jun 01, 2010 10:56 am
by Creature
I'll guess I'll post it before anyone else does:
  • I don't think this belongs in OS Development, but rather in General Programming.
  • This is something you should have known (preferably you should have known it all along because you known your language, but otherwise through a quick Google).
  • This question has been asked a couple times before, so you should be able to find it by performing a forum search.

Re: Static variables in classes not allowed

Posted: Tue Jun 01, 2010 11:58 am
by Karlosoft
I knew. Simply I forgot to initialize the value, it could happen, everybody does mistakes.
If I knew my mistake I can have looked for on google, but how can you do a search without knowing what to search?

Re: Static variables in classes not allowed

Posted: Tue Jun 01, 2010 12:01 pm
by Combuster
google has a nice trait of showing interesting things when you feed it the error message...

Re: Static variables in classes not allowed

Posted: Tue Jun 01, 2010 12:03 pm
by fronty
What about "c++ static member linker error"? First hit contained the answer.

If you can't look for a solution for your error becaue you don't know your error, search for the error using symptoms of it.

Re: Static variables in classes not allowed

Posted: Tue Jun 01, 2010 12:54 pm
by Karlosoft
The error was something like, bss section limit reached, from 0xf8000 up to ....., and than all the many reference failed. How can I had related the error limit reached with a problem of this kind?

It doesn't matter, If you want you could remove this post, now the code works. Getting angry for this is no-sense :)