开发者

What are the differences in the meaning of "static" in C++ and Objective C?

开发者 https://www.devze.com 2023-02-01 22:45 出处:网络
Objective-C and C++ belong to the C family, so in terms of \"static\", there are static variables, static functions, static classes etc.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号