Warrior
Warrior

Reputation: 39374

How to declare a static integer in h class in iPhone?

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

Answers (1)

Chuck
Chuck

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

Related Questions