Static block usage

Hello

I'm beginner in cpp programming. I'm confused about static block usage in cpp code
so should any one explain about usage of static block.




Thanks & Regards
Ramanjaneya. K
Static block? Do you mean static variables or static functions?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
static int x; // global variable is visible only in this translation unit

static void f() // global function is visible only in this translation unit
{
}

void g()
{
    static int a; // behaves like a global visible only in this function
}

class Tmp
{
    static int b; // all objects of type Tmp will see the same b

public:

    static void sf() // function can be used without an instantiation
    {
    }
};

int Tmp::b; // b must be defined externally 


http://en.wikipedia.org/wiki/Translation_unit_%28programming%29
http://en.wikipedia.org/wiki/Static_variable
http://en.wikipedia.org/wiki/Static_%28keyword%29
http://yosefk.com/c++fqa/fqa.html#fqa-10.11
https://publib.boulder.ibm.com/infocenter/comphelp/v8v101/topic/com.ibm.xlcpp8a.doc/language/ref/cplr039.htm
Last edited on
Topic archived. No new replies allowed.