static-members

Non-static members not accessible in static function

北战南征 提交于 2019-12-04 05:42:24
问题 I have defined a function HRESULT AMEPreviewHandler:: CreateHtmlPreview() { ULONG CbRead; const int Size= 115000; char Buffer[Size+1]; HRESULT hr = m_pStream->Read(Buffer, Size, &CbRead ); //this m_pStream is not accessible here even it is declared globally. the program is asking me to // declare it static because this CreateHtmlPreview() function called //inside the Static function (i mean here :-static CreateDialog\WM_Command\CreateHtmlPreview();) //but if i declare it static the two

Access to static properties via this.constructor in typescript

ぃ、小莉子 提交于 2019-12-03 22:31:48
I want to write es6 class: class SomeClass { static prop = 123 method() { } } How to get access to static prop from method() without use SomeClass explicitly? In es6 it can be done with this.constructor , but in typescript this.constructor.prop causes error " TS2339: Property 'prop' does not exist on type 'Function' ". but in typescript this.constructor.prop causes error "TS2339: Property 'prop' does not exist on type 'Function'". Typescript does not infer the type of constructor to be anything beyond Function (after all ... the constructor might be a sub class). So use an assertion: class

What is the best way to initialize a complex static member in Java?

纵然是瞬间 提交于 2019-12-03 21:32:31
My objective is to have a private static Properties object in my class, to act as defaults when creating other Properties objects needed by my application. The current implementation looks like this: public class MyClass { private static Properties DEFAULT_PROPERTIES = new Properties(); static { try { DEFAULT_PROPERTIES.load( MyClass.class.getResourceAsStream("myclass.properties")); } catch (IOException e) { throw new RuntimeException(e); } } } Looking at it, it works, but it doesn't feel right. How would you do it? There are basically two ways. First way is using the static block as you have

What is better: Static variable V.S. Asp.NET Application Session?

筅森魡賤 提交于 2019-12-03 18:03:34
问题 Say you want to share some resource, like a class or a variable across all threads/sessions within a ASP.NET web application. What is better? 1) A static variable having thread-safe accessors to that static variable? 2) Or a ASP.NET application session variable? 回答1: If you only have one of those, there is little difference. If you have several, you should use static variables rather than Application variables. The Application.Lock method will lock all Application variables, while you can use

error LNK2001: unresolved external symbol "private: static class

左心房为你撑大大i 提交于 2019-12-03 17:07:39
问题 error LNK2001: unresolved external symbol "private: static class irrklang::ISoundEngine * GameEngine::Sound::_soundDevice" (?_soundDevice@Sound@GameEngine@@0PAVISoundEngine@irrklang@@A) I cannot figure out why i am receiving this error. I believe i am initializing correctly. Can anyone lend a hand? sound.h class Sound { private: static irrklang::ISoundEngine* _soundDevice; public: Sound(); ~Sound(); //getter and setter for _soundDevice irrklang::ISoundEngine* getSoundDevice() { return

Is it possible to declare a virtual static constant value in a C++ class?

邮差的信 提交于 2019-12-03 15:56:40
问题 I'd like to have a base class that has a constant field (like an unique ID associated with the class that can't be modified after compile time). So far the static const declaration would be just fine. Now, I'd like to inherit this base class and make sure that the children of this class do have the same field, but with their own values. How can I do this? Let's say, I'd like to have a base class called Base with an ID field that holds the int value of 0. Then, I'd like to have the classes A ,

Can template classes have static members in C++

淺唱寂寞╮ 提交于 2019-12-03 15:44:14
问题 Can a template class in C++ have static members? Since it doesn't exist and is imcomplete before it is used, is this possible? 回答1: Yes. The static member is declared or defined inside the template< … > class { … } block. If it is declared but not defined, then there must be another declaration which provides the definition of the member. template< typename T > class has_static { // inline method definition: provides the body of the function. static void meh() {} // method declaration:

get static initialization block to run in a java without loading the class

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 14:21:41
I have a few classes as shown here public class TrueFalseQuestion implements Question{ static{ QuestionFactory.registerType("TrueFalse", "Question"); } public TrueFalseQuestion(){} } ... public class QuestionFactory { static final HashMap<String, String > map = new HashMap<String,String>(); public static void registerType(String questionName, String ques ) { map.put(questionName, ques); } } public class FactoryTester { public static void main(String[] args) { System.out.println(QuestionFactory.map.size()); // This prints 0. I want it to print 1 } } How can I change TrueFalseQuestion class so

Static block vs static method - initializing static fields

[亡魂溺海] 提交于 2019-12-03 12:57:44
问题 Out of curiosity, I measured the performance between static block and static method initializer. First, I implemented the above mentioned methods in two separate java classes, like so: First: class Dummy { static java.util.List<Integer> lista = new java.util.ArrayList<Integer>(); static { for(int i=0; i < 1000000; ++i) { lista.add(new Integer(i)); } } } public class First { public static void main(String[] args) { long st = System.currentTimeMillis(); Dummy d = new Dummy(); long end = System

Static variables in web applications

梦想与她 提交于 2019-12-03 12:18:15
Can I use static variables in my web application ? what are the alternatives to static ? When I use static variables in pages and more than one user use the application, it makes conflict data (incorrect data). What are the limits of using static members? Are static members shared in memory? Consider storing your shared variables in the HttpApplication object or in the Cache object. However, if you are trying to store values for each user separately, you should store those values in a Session variable. Static variables inside Asp.Net are shared in the memory space of the w3svc.exe process and