static, can I under stand like this?:

once anything is is declared as static, it will always exist in the memory, and all the same class or function or variable will use the same memory block until the whole program finish, right?
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
26
27
28
29
30
31
32
33
34
35
36
37
38
class XL{
int i;
static int s;
public:  
	XL(int ii) // constructor
	{ 
		i = ii; 
		cout << "I am constructor\n" << endl; 

	}
	~XL()
	{
		cout << "I am destructor\n" << endl; 
	}

	static int func(int i)
	{
		s = i;
		return s;
	}
};


int main()
{

		
	cout << XL::func(34) << endl;



	return 0;
}




Topic archived. No new replies allowed.