Tag Archives: static variables

The extern Keyword

After all the recent posts about statics, I wanted to talk about the extern keyword before moving onto something different. Do you remember the problem we had with our “global” static variable in this post? If you haven’t read it, the code example illustrated that static variables are only available to code in the translation […]

Static Variables In Template Classes And Methods

This is the final post in a series on static variables, and in it I’ll talk about the final place we can put them – in template classes or functions. If you’ve been following along, and you have a good understanding of how template classes work, you can almost certainly deduce how static variables will […]

Static Variables In C++ Classes

It turns out that static variables in C++ classes are actually pretty cool. If you declare a static variable at class level (i.e. inside the class declaration), then you are creating a variable that will a) be accessible to all objects created from that class, and b) be available even before you have created a […]

Static Variables In C And C++ – Function Level

We’ve looked at file level static variables, so now let’s see what happens when you put them in a function. If you declare a static variable at function level (i.e. inside an normal function, not a class method), then you are creating a variable that will: a) be instantiated the first time the function is […]