static-members

Static properties in Swift

自古美人都是妖i 提交于 2019-12-17 06:27:43
问题 I'm trying to convert the following Objective-C code to Swift. In my Objective-C code, there's a static variable and its accessed from a class method. @implementation SomeClass static NSMutableArray *_items; + (void)someMethod { [_items removeAll]; } @end Since you can't access types declared like this private var items = [AnyObject]() from class functions in Swift, I created a stored property for it like this. class var items: [AnyObject] { return [AnyObject]() } And I'm trying to call a

C# Static variables - scope and persistence

风流意气都作罢 提交于 2019-12-17 04:29:22
问题 I just did a little experiment: public abstract class MyClass { private static int myInt = 0; public static int Foo() { return myInt; } public static int Foo(int n) { myInt = n; return bar(); } private static int bar() { return myInt; } } and then I ran: MessageBox.Show(MyClass.Foo().ToString()); MessageBox.Show(MyClass.Foo(3).ToString()); MessageBox.Show(MyClass.Foo().ToString()); MessageBox.Show(MyClass.Foo(10).ToString()); MessageBox.Show(MyClass.Foo().ToString()); The results I expected

Do static members ever get garbage collected?

好久不见. 提交于 2019-12-17 02:31:45
问题 Do static member variables ever get garbage collected? For example, let's use the following class. public class HasStatic { private static List<string> shared = new List<string>(); } And supposed that it's used like this: //Startup { HasStatic a = new HasStatic(); HasStatic b = new HasStatic(); HasStatic c = new HasStatic(); HasStatic d = new HasStatic(); //Something } //Other code //Things deep GC somewhere in here HasStatic e = new HasStatic(); When a , b , c , and d are garbage collected

C++ Static member initialization (template fun inside)

可紊 提交于 2019-12-17 02:31:45
问题 For static member initialization I use a nested helper struct, which works fine for non templated classes. However, if the enclosing class is parameterized by a template, the nested initialization class is not instantiated, if the helper object is not accessed in the main code. For illustration, a simplified example (In my case, I need to initialize a vector). #include <string> #include <iostream> struct A { struct InitHelper { InitHelper() { A::mA = "Hello, I'm A."; } }; static std::string

Do static members ever get garbage collected?

好久不见. 提交于 2019-12-17 02:30:08
问题 Do static member variables ever get garbage collected? For example, let's use the following class. public class HasStatic { private static List<string> shared = new List<string>(); } And supposed that it's used like this: //Startup { HasStatic a = new HasStatic(); HasStatic b = new HasStatic(); HasStatic c = new HasStatic(); HasStatic d = new HasStatic(); //Something } //Other code //Things deep GC somewhere in here HasStatic e = new HasStatic(); When a , b , c , and d are garbage collected

C++ Static member initialization (template fun inside)

邮差的信 提交于 2019-12-17 02:30:05
问题 For static member initialization I use a nested helper struct, which works fine for non templated classes. However, if the enclosing class is parameterized by a template, the nested initialization class is not instantiated, if the helper object is not accessed in the main code. For illustration, a simplified example (In my case, I need to initialize a vector). #include <string> #include <iostream> struct A { struct InitHelper { InitHelper() { A::mA = "Hello, I'm A."; } }; static std::string

C++ undefined reference (static member) [duplicate]

时间秒杀一切 提交于 2019-12-14 02:43:24
问题 This question already has answers here : static variable link error (2 answers) Closed 4 years ago . Possible Duplicate: C++: undefined reference to static class member Logger.h: class Logger { private: Logger(); static void log(const string& tag, const string& msg, int level); static Mutex mutex; public: static void fatal(const string&, const string&); static void error(const string&, const string&); static void warn(const string&, const string&); static void debug(const string&, const

Java: how to reference a non-static field of an outer class from a static nested class?

前提是你 提交于 2019-12-13 16:25:43
问题 Is there a way to refer to a non-static field of an outer class from a static nested class? Please see my code below: public class TestComponent { String value; public void initialize(String value) { this.value = value; } public static class TestLabel extends GenericForwardComposer { Label testLabel; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); testLabel.setValue(value); } } } This code throws an error at testLabel.setValue(value) as I am

DialogProc function asking to declare it self static [duplicate]

橙三吉。 提交于 2019-12-13 07:15:53
问题 This question already has answers here : Non-static members not accessible in static function (4 answers) Closed 5 years ago . here is my createdialogparam function which is calling DialogProc function from here- HRESULT AMEPreviewHandler::CreatePreviewWindow() { assert(m_hwndPreview == NULL); assert(m_hwndParent != NULL); HRESULT hr = S_OK; m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this); /here the dialog proc

Lifecycle of Static Variables

ぐ巨炮叔叔 提交于 2019-12-13 05:51:30
问题 Is there any way to set the life cycle of a static variable - ie: how long it's kept alive before being reset? I was hoping there may be an attribute which can be applied. 回答1: Static members are associated with the type itself, not with an instance of the type. Therefore their lifecycle is limited to the timing and ordering of their creation, and they don't get "reset" by instances of the type. 回答2: The lifetime of a value in a Static variables is the same as it's containing AppDomain. Ie.