static-members

Random number generation in MVC applications

What is the correct way of generating random numbers in an ASP.NET MVC application if I need exactly one number per request? According to MSDN, in order to get randomness of sufficient quality, it is necessary to generate multiple numbers using a single System.Random object, created once. Since a new instance of a controller class is cre...

Class decorator to declare static member (e.g., for log4net)?

I'm using log4net, and we have a lot of this in our code: public class Foo { private static readonly ILog log = LogManager.GetLogger(typeof(Foo)); .... } One downside is that it means we're pasting this 10-word section all over, and every now and then somebody forgets to change the class name. The log4net FAQ also mentions th...

PHP: Extending static member arrays

I'm having the following scenario: class A { public static $arr=array(1,2); } class B extends A { public static $arr=array(3,4); } Is there any way to combine these 2 arrays so B::$arr is 1,2,3,4? I don't need to alter these arrays, but I can't declare them als const, as PHP doesn't allow const arrays.http://stackoverflow.com/questio...

undefined reference to static member variable

Hi. 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 I...

conflicting declaration when filling a static std::map class member variable

I have a class with a static std::map member variable that maps chars to a custom type Terrain. I'm attempting to fill this map in the class's implementation file, but I get several errors. Here's my header file: #ifndef LEVEL_HPP #define LEVEL_HPP #include <bitset> #include <list> #include <map> #include <string> #include <vector> #...

Initialize static members in PHP

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: Ok...

How to auto-increment reference number persistently when NSManagedObjects created in core-data.

In my application i am using core-data to store information and saving these data to the server using web-connectivity i have to use MySql. Basically what i want to do is to keep track of number of NSManagedObject already created and Whenever i am adding new NSManagedObject, based on that counting it will assign the class a Int_value whi...

Inheritance and storing static class information

I'm trying to set up some stuff with Lua, but the specifics of Lua aren't important for my question. What I would like to be able to do is call a function, say OpenLib<T>(L), and have it get the table name for a particular class (as well as it's table) and register it with Lua. It essentially boils down to this: template <class T> sta...

Sharing static members between template instantiations? (impossible?)

I am doing something that is probably silly, but it would be nice if it worked. I am attempting to specialize types in a way that I need my own lookup structure that is essentially global (but ideally encapsulated as a class variable), but I want the objects to be type safe, so they are parameterized. Consequently, I have, essentially ...

Seq seq type as a member parameter in F#

Hi, why does not this code work? type Test() = static member func (a: seq<'a seq>) = 5. let a = [[4.]] Test.func(a) It gives following error: The type 'float list list' is not compatible with the type 'seq<seq<'a>>' ...

using static classes for global objects in C#

I am using a list for particles. List<Particle> particles; Normally i place this list in my Simulation class. Which calculates position, velocity and other properties of particles. A few other classes need this particle data for output and post processing. is it OK to create a static class, static class Particles { static List<...

How to force static class to implement specific methods?

I need to create a set of static classes and all of them need to implement the same methods. I want to find a way to force them so. I understand that static classes cannot derive anything other than System.Object. Should I use non-static methods for this? It could be, but none of the methods of this class will use instance properties......

Why keyword 'this' cannot be used in a static method?

Why can't the keyword this be used in a static method? I am wondering why C# defines this constraint. What benefits can be gained by this constraint? [Update]: Actually, this is a question I got in an interview. I do know the usage of 'static' and 'this', based on all your response, I guess I know a little of why the two can not be use...

C++ definition of dllimport static data member

Hi, I do have a class which looks like below: //.h file class __declspec(dllimport) MyClass { public: //stuff private: static int myInt; }; // .cpp file int MyClass::myInt = 0; I get the following compile error: error C2491: 'MyClass::myInt' : definition of dllimport static data member not allowed what should I d...

Generic question... Calling a static method from a generic class...

Hi! I have a generic class: public class MyList<LinkedItem> : List<LinkedItem> where LinkedItem : MyItem, new() { } From that generic class, I would like to access a static function from the LinkedItem Class which is a descendant of MyItem class. (thus without creating an instance of the LinkedItem). Is it possible? Thank you, Eri...

Locking to modify static value-type member. Is it necessary?

I have a CacheHelper class to facilitate interaction with the cache. I want to use a static int field to specify my cache timeout. The field is initially set to a const default value but I want to provide a way for the application to change the default timeout value. Do you need to lock when modifying a static value type? Is the lock i...

vb.net static variables on a web garden

Do vb.net static variables work on an IIS web garden? ...

Have I found a bug in Clang?

I tried to compile the code below with Clang class Prasoon{ static const int dummy = 0; }; int const Prasoon::dummy = 0; int main(){} The above code did not give any error when compiled with Clang. prasoon@prasoon-desktop ~ $ clang++ --version clang version 2.8 (trunk 107611) Target: i386-pc-linux-gnu Thread model: posix prasoo...

Lock acquistion on static members within a Java Class

Hi, I am currently resolving a performance degradation issue due to heavy lock contention. I am considering "Lock splitting" to resolve this issue. The skeletal usage pattern is :: CURRENT USAGE :: public class HelloWorld{ public static synchronized method1(){ //uses resource 1 } public static synchronized method2(){...

Can IWindsorContainer be instantiated through a static method?

I'm still groping around a bit with Castle Windsor. At the moment all my pages which need an IWindsorContainer instantiate one themselves through a property: private IWindsorContainer WindsorContainer { get { if (_windsorContainer == null) { _windsorContainer = new WindsorContainer(new XmlInterpreter(Server...