What are the differences in the meaning of "static" in C++ and Objective C?
Objective-C and C++ belong to the C family, so in terms of "static", there are static variables, static functions, static classes etc.
Static has static storage, lifecycle, scope.
Here is the q开发者_StackOverflowuestion:
- What are the big differences in the meaning of "static" in C++ and Objective C?
static
has the exact same meaning in Objective-C that it would have in C. It does not mean the same thing as in C++. In C++, static
is additionally used to declare and define class methods (methods which can only be called on the class itself) and variables, but Objective-C distinguishes class and instance methods with different syntax:
+ (void)classMethod;
- (void)instanceMethod;
and does not support class variables.
static
in Objective-C is identical to its plain C counterpart (specifying the variable linkage). While C++ supports this usage of static
, it extends the meaning of the static
keyword to declaring class methods as well.
精彩评论