关于静态成员变量范围的问题 [英] Question about scope of static member variable

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

问题描述

全部,


当我创建一个带有静态成员变量的类并且在控制台应用程序中引用

类时,它看起来好像每个实例都是

应用程序有自己独立的成员变量副本。


因此,看起来静态类成员的范围是

仅限于在机器上运行的应用程序的特定实例。


这是正确的吗?
< br $> b $ b谢谢,


- 乔纳森

All,

When I create a class with a static member variable and reference that
class in a console applicaton it appears as though each instance of the
application has its own separate copy of the member variable.

Therefore, it would appear that the scope of a static class member is
limited to a specific instance of an application that happens to be
running on the machine.

Is this correct?

Thanks,

--Jonathan

推荐答案

"是ne ************ @ hotmail.com" <是ne ************ @ hotmail.com>写道:
"ne************@hotmail.com" <ne************@hotmail.com> wrote:
当我创建一个带有静态成员变量的类并且在控制台应用程序中引用它时,它看起来好像每个
应用程序的实例都有它自己的成员变量的单独副本。

因此,看起来静态类成员的范围仅限于某个应用程序的特定实例,该实例恰好是
在机器上运行。

这是正确的吗?
When I create a class with a static member variable and reference that
class in a console applicaton it appears as though each instance of the
application has its own separate copy of the member variable.

Therefore, it would appear that the scope of a static class member is
limited to a specific instance of an application that happens to be
running on the machine.

Is this correct?




每个应用程序都在自己的地址空间中运行,并带有自己的变量,
除非你努力工作(通过共享内存或其他技术)制作

否则。


- Barry



Every application runs in its own address space with its own variables,
unless you work hard (via shared memory or some other technique) to make
it otherwise.

-- Barry


你好,巴里!


BK>每个应用程序都在自己的地址空间中运行,并带有自己的变量,

BK>除非你努力工作(通过共享内存或其他技术)

BK>否则。


静态var的范围可以通过ThreadStaticAttribute限制在线程的范围内。

-

此致,Vadym Stetsyak

www: http://vadmyst.blogspot.com


" Vadym Stetsyak" < VA ***** @ ukr.net>写道:
"Vadym Stetsyak" <va*****@ukr.net> wrote:
你好,巴里!

BK>每个应用程序都在自己的地址空间中运行,并有自己的变量,
BK>除非你努力工作(通过共享内存或其他技术),否则BK>否则。

静态var的范围可以通过ThreadStaticAttribute限制在线程的范围内。
Hello, Barry!

BK> Every application runs in its own address space with its own variables,
BK> unless you work hard (via shared memory or some other technique) to
BK> make it otherwise.

Scope of static var can be limited to the scope of the thread via ThreadStaticAttribute.




OPs问题涉及到多个控制台应用程序的实例

不共享静态变量的值。


- Barry



The OPs question relates to multiple instances of a console application
not sharing the value of a static variable.

-- Barry


这篇关于关于静态成员变量范围的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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