static-members

Is the ConcurrentDictionary thread-safe to the point that I can use it for a static cache?

倖福魔咒の 提交于 2019-12-03 08:35:24
问题 Basically, if I want to do the following: public class SomeClass { private static ConcurrentDictionary<..., ...> Cache { get; set; } } Does this let me avoid using lock s all over the place? 回答1: Yes, it is thread safe and yes it avoids you using locks all over the place (whatever that means). Of course that will only provide you a thread safe access to the data stored in this dictionary, but if the data itself is not thread safe then you need to synchronize access to it of course. Imagine

Can template classes have static members in C++

瘦欲@ 提交于 2019-12-03 05:29:00
Can a template class in C++ have static members? Since it doesn't exist and is imcomplete before it is used, is this possible? 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: definition with the body must appear later static void fuh(); // definition of a data member (i.e., declaration

error LNK2001: unresolved external symbol \"private: static class

拈花ヽ惹草 提交于 2019-12-03 05:24:22
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 _soundDevice; } // void setSoundDevice(irrklang::ISoundEngine* value) { _soundDevice = value; } static bool

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

别说谁变了你拦得住时间么 提交于 2019-12-03 05:18:48
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 , B and C , all of them being public children of Base and I'd like to make sure that these children

Is the ConcurrentDictionary thread-safe to the point that I can use it for a static cache?

社会主义新天地 提交于 2019-12-03 00:00:53
Basically, if I want to do the following: public class SomeClass { private static ConcurrentDictionary<..., ...> Cache { get; set; } } Does this let me avoid using lock s all over the place? Yes, it is thread safe and yes it avoids you using locks all over the place (whatever that means). Of course that will only provide you a thread safe access to the data stored in this dictionary, but if the data itself is not thread safe then you need to synchronize access to it of course. Imagine for example that you have stored in this cache a List<T> . Now thread1 fetches this list (in a thread safe

Help understanding PHP5 error

僤鯓⒐⒋嵵緔 提交于 2019-12-02 21:33:23
问题 In short.. question is... "Say what?" To expand... "I don't get the error" Strict Standards: Non-static method Pyro\Template::preLoad() should not be called statically, assuming $this from incompatible context in /opt/lampp/htdocs/dc/pyro/app/controllers/admin/courses.php on line 14 public function actionIndex() { $this->data->users = $this->DB->query("SELECT id, name, description FROM :@courses")->getAll(); $this->data->title = 'Courses'; $this->data->content_area = \Pyro\Template::preLoad(

What is the correct way to initialize static data members in C++ (98, 11 and 14)

爷,独闯天下 提交于 2019-12-02 18:57:36
What is the right way to initialize static data members in C++? I'm also interested in how it has changed from C++98, to C++11 to C++14. Here is an example: // bufferedOutput.h class BufferedOutput { // Static member declaration. static long bytecount; }; // bufferedOutput.cpp long BufferedOutput::bytecount = 50; Are there other ways to initialize static data members? The rules have always been as follows: A const static data member (SDM) of integral or enumeration type can be initialised in class with a constant expression. A constexpr SDM must be initialised in class with a constant

Access Form controls from static class [duplicate]

怎甘沉沦 提交于 2019-12-02 18:35:56
问题 This question already has answers here : How does one access a control from a static method? (10 answers) Closed last year . 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

Initialize static members in PHP

无人久伴 提交于 2019-12-02 12:32:48
问题 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 :) 回答1: From the docs, "Like any other PHP static variable, static properties may only be initialized

Local variable vs static variable memory and performance

不羁的心 提交于 2019-12-02 11:39:07
问题 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