Reputation: 39374
I am not able to declare a static integer in h class in iPhone.
static int i;
This gives an error:
expected specifier-qualifier list before static
How to resolve this? How can I declare a static variable globally in iPhone?
Upvotes: 0
Views: 1461
Reputation: 237010
There is no such thing as a global static variable. A static variable has file scope — and for .h files, that means every file it's included in gets a different variable called i
. To declare a global variable, put the declaration extern int i
in your header and just int i
in the global scope in one implementation file (it doesn't technically matter which one).
Upvotes: 1