方法调用中的静态变量 [英] static variable in method call

查看:124
本文介绍了方法调用中的静态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在方法中创建本地静态变量,那么每个实例都初始化一次,或者每个程序初始化一次。

If you create a local static variable inside a method, is that initialised once per instance, or once per program?

这在C ++和Objective-C ?

Does this differ between C++ and Objective-C?

推荐答案


如果在方法中创建本地静态变量, ,或每个节目一次?

If you create a local static variable inside a method, is that initialised once per instance, or once per program?

即使是每个节目一次,每个节目一次

Once per program.

它是在非静态类成员函数中,它不与任何类实例相关联;在整个程序中只有一个变量实例,只初始化一次。

Even if it is in a non-static class member function, it is not associated with any class instance; there will only be one instance of the variable in the whole program, initialised just once.


C ++和Objective-C之间是否有区别?

Does this differ between C++ and Objective-C?

在C ++中,它在第一次调用函数时初始化。在C(和Objective-C)中,它在程序启动之前被初始化。在实践中,这没有什么区别,因为初始化在C中不会有任何副作用。

In C++, it is initialised the first time the function is called. In C (and Objective-C), it is initialised prior to program startup. In practice, this doesn't make a difference, since the initialisation can't have any side effects in C.

这篇关于方法调用中的静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆