Static variables in classes not allowed

Programming, for all ages and all languages.
Post Reply
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Static variables in classes not allowed

Post 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 :)
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Static variables in classes not allowed

Post by Karlosoft »

Thank you! It works :)
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Static variables in classes not allowed

Post 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.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Static variables in classes not allowed

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Static variables in classes not allowed

Post by Combuster »

google has a nice trait of showing interesting things when you feed it the error message...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
fronty
Member
Member
Posts: 188
Joined: Mon Jan 14, 2008 5:53 am
Location: Helsinki

Re: Static variables in classes not allowed

Post 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.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Static variables in classes not allowed

Post 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 :)
Post Reply