static-members

Access Form controls from static class [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-02 10:50:52
This question already has an answer here: How does one access a control from a static method? 10 answers I have a Form1 with lots of controls and I need to access/edit control values from another static class. Since I have lots of controls on the form, it takes some time to define set and get from every single of them. I am wondering if there is any way that I can define an instance of the Form1 within the static class so that I can have access to all controls of Form1 in this class? Here is the structure of the static class: public static class Glob { public static int int1; public static int

What are static and dynamic variables / methods in OOP?

社会主义新天地 提交于 2019-12-02 09:36:41
I am trying to better understand basic concepts in OOP. What are static and dynamic variables and methods in object-oriented programming? What is, for instance, the difference between using $this vs. double colon (::)? $this ($this->a_method()) Advantages: ?. Disadvantages: ? ... "this" is not self-documenting as in: $this->method_from_an_extended_class() . Double colon (someclass::a_method()) Advantages: ? Disadvantages: ? "Static" and "dynamic" aren't the right descriptions for that. -> indicates a instance functions or instance data , meaning that the function or data has an implicit $this

Local variable vs static variable memory and performance

我与影子孤独终老i 提交于 2019-12-02 07:09:40
Where are static variables stored inside a non static method call? I.e. Inside CalculateTotalStatic() , we are incrementing the static member MyStaticVariableHolder.Total and are also comparing the variable i with MyStaticVariableHolder.TotalArray.Length within the for loop. On the other hand, in another version of this method CalculateTotalLocal() , we are using local variables declared within the method to perform both the above actions. During CalculateTotalLocal , there will be two additional variables placed on the stack which will hold their values on the stack itself ( localTotal and

Initialize static members in PHP

醉酒当歌 提交于 2019-12-02 05:55:37
class Person { public static function ShowQualification() { } } class School { public static $Headmaster = new Person(); // NetBeans complains about this line } Why is this not possible? I want to be able to use this like School::Headmaster::ShowQualification(); ..without instantiating any class. How can I do it? Update: Okay I understood the WHY part. Can someone explain the HOW part? Thanks :) From the docs , "Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed." new Person() is not a literal or a constant, so

C++ static data members initialization

蹲街弑〆低调 提交于 2019-12-02 03:33:58
1) Is it true that static data members of classes always get initialized before main() called? 2) Is it true that "static initialization order fiasco" can happen if static data member of class initialization code uses global static variable of other translation unit? Where can I read more about it? I couldn't find answer in 2003 standard of C++. Thanks a lot. 1) Is it true that static data members of classes always get initialized before main() called? yes they would always be initialized before program starts executing. 2) Is it true that "static initialization order fiasco" can happen if

Template static members initialization order

一笑奈何 提交于 2019-12-02 03:06:52
问题 I have a question related to a previous question posted here Static field initialization order Suppose I have the following struct, with 2 static members x and y (templated types themselves) #include <iostream> using namespace std; template <typename T> struct Foo { static T x; static T y; Foo() { cout << "x = " << x << endl; cout << "y = " << y << endl; } }; template <typename T> T Foo<T>::x = 1.1f; template <typename T> T Foo<T>::y = 2.0 * Foo<T>::x; int main() { Foo<double> foo; } Output:

undefined reference to static member variable

℡╲_俬逩灬. 提交于 2019-12-02 03:03:00
问题 I have this class that has a static member. it is also a base class for several other classes in my program. Here's its header file: #ifndef YARL_OBJECT_HPP #define YARL_OBJECT_HPP namespace yarlObject { class YarlObject { // Member Variables private: static int nextID; // keeps track of the next ID number to be used int ID; // the identifier for a specific object // Member Functions public: YarlObject(): ID(++nextID) {} virtual ~YarlObject() {} int getID() const {return ID;} }; } #endif and

undefined reference to static member variable

断了今生、忘了曾经 提交于 2019-12-02 00:42:30
I have this class that has a static member. it is also a base class for several other classes in my program. Here's its header file: #ifndef YARL_OBJECT_HPP #define YARL_OBJECT_HPP namespace yarlObject { class YarlObject { // Member Variables private: static int nextID; // keeps track of the next ID number to be used int ID; // the identifier for a specific object // Member Functions public: YarlObject(): ID(++nextID) {} virtual ~YarlObject() {} int getID() const {return ID;} }; } #endif and here's its implementation file. #include "YarlObject.hpp" namespace yarlObject { int YarlObject::nextID

Why we have to define a const static member that is initialized within a class

橙三吉。 提交于 2019-12-02 00:14:40
As we know,It is possible to initialize integral const static members inside the class structure.This is useful when the constant is used in the class structure after the initialization.For example,it can be used as the size of an int array. Look the code following: class MyClass{ static const int num = 100; int elems[num]; ... }; But we still have to define the member num outside the class definition: const int MyClass::num; I don't know why we have to do like this. Could someone tell me why? Thanks a lot. In addition,I write the following code: #include <iostream> using namespace std; class

Why can I access the private members of an enclosing class reference

杀马特。学长 韩版系。学妹 提交于 2019-12-02 00:13:49
I have seen many questions about accessing private members of an enclosing class. However, my question is the opposite. If I have (as an example), the following code: public class A { private String outerString = "silly string"; static class B { private final A someA = new A(); public void foo() { String b = someA.outerString ; } } } I'm wondering why this compiles? I would have expected an error by virtue of the way in which I am accessing the 'outerString' instance variable from class A (via someA.outerString). I know that an inner class can access the enclosing class members directly by an