static

using static methods or instantiate the class?

Hi, recently i've got a dispute about using static methods in a class that is used by hundreds threads. In my opinion the "first" solution has no special benefits except it is easier to use for the client of class but i have been told that it is extremely bad idea and I have to use the "second" solution. Can anyone give me clear explan...

Java - Get reference to a static class using reflection

In Java, is it possible to access an instance of a static class (nested) using reflection? Supposing I have the following 2 classes defined in the package Package1.SubPackage.SubSubPackage: public class MyMainClass { public static class SalesObjectGrouper1 { public static final GrouperContext CONTEXT = new GrouperContext("...

PHP Static Method Using Private Class Functions/Variables

If I write a public static method in a class ie... public static function get_info($type){ switch($type){ case'title': self::get_title(); break; } } I have to write my get_title() function as public... public static function get_title(){ return 'Title'; } ...

linkage error with non-member functions

------------------blah.h------------------------ #pragma once namespace SomeNamespace{ static void someMethod(){} } -----------------blah.c-------------------------- #include “blah.h” int main(int argc, char**argv){ SomeNamespace::someMethod(); return 0; } The above works fine but if I omit ‘static’ I get: >stdafx.obj : error LNK...

iPhone Static Library Initialization Popup

I have a static library build for iPhone/iPad and I want to show a pop up right at the initialization (before the main). My library initialize itself with: int InitLibrary( void ) __attribute__( ( constructor ) ); And Im trying to put the following code inside InitLibrary: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[ NS...

Public static methods - a bad sign?

I've just read this article here: http://hamletdarcy.blogspot.com/2008/04/10-best-idea-inspections-youre-not.html, and the last bit in particular got me thinking about my code, specifically the advice: What in the world is a public method doing on your object that has no dependency on any fields within the object? This is certainly a...

Is it possible to access an instance variable via a static method?

Hi, In C#, is it possible to access an instance variable via a static method in different classes without using parameter passing? In our project, I have a Data access layer class which has a lot of static methods. In these methods SqlCommand timeout value has been hard-coded. In another class(Dac) in our framework there has been many...

__attribute__((init_priority(X))) in GCC

I'm using __attribute__((init_priority(X))) in GCC like this: Type1 __attribute__ ((init_priority (101))) name1 = value1; Type2 __attribute__ ((init_priority (102))) name2 = value2; in different source files. Let's say file1.cpp and file2.cpp. If I use this in same library it works as expected, name1 is initialized before name2 but i...

class variable is reset each request

i hava a class that hold a list for each request but each request the list is empty again what can i do to make it live here is my class , i want the list to hold values from previews requests (yes each request i'm settings a value there ) class Sessions{ private static $list = array(); .... ..... } ...

Problem with the List - Java

I am trying to create a new instance of Couple with the given name and gender and add to the collections of couples, in the addCouple method. I have another class called Couple. In that class I have getters and Setters one for name and the gender. I tried to use the bulk operation for the list: List<Dating> list1 = new ArrayList<Dating>...

C++ static members

Hello! I have the following code: void Foo() { static std::vector<int>(3); // Vector object is constructed every function call // The destructor of the static vector is invoked at // this point (the debugger shows so) // <------------------- int a; } Then somewhere I call Foo several times in a sequence Why doe...

IIS recycle causes error in static dataset access

In the asp.net webservice, I have a static dataset that loads data (synchronized) upon first time access. However, when IIS recycle the app pool, I have exception thrown because of "Collection was modified; enumeration operation might not execute." The recycle will start the new process, which will create new static dataset, the request...

PHP: call child constructor from static method in parent

I want to have a static method in a parent class that creates instances of whatever subclass i call this method on. An example to make this more clear: class parent { public static method make_objects($conditions){ for (...){ // here i want to create an instance // of whatever subclass i am calling ...

Accessing Static Variable from child->child class php

I have the following setup: <?php class core { static $var1; } class parent extends core { function getStatic() { return parent::$var1; } } class child extends parent { function getStatic() { // I want to access core static var, how can i do it? //return parent::$var1; } } ?> I need to be able...

Are many static variables in functions using up to much memory?

Hi, I want to write a cross-plattform wrapper for some OS specific (Linux/MacOSX/Windows) calls to get the number of cores of the CPU etc. My idea was to put all of them in single functions with static variables, so stuff like the number of cores that does not change will be processed only once. int getNumCPUCores() { static int nu...

Add images, string file to static library in iPhone

I want to make a static library which basically displays some views and button. My client wants this to be distributed as a library to be used by other iPhone developers. My doubts are Can we add images and other resources to the library .a file? How can we include localization to this static library?(localizable.strings??) ...

Does Android ensure that an Activity is a singleton?

If an Activity is a singleton in practice, I think I can gain some efficiency by declaring appropriate members "static", with zero risk. Yes? ...

Global Static Class with Objects

Ok, so I know you can't have objects in a static class but i need a class that i can hold objects that are accessible from different classes. I am making a dll that will provide extended functionality to another program so i can't just inherit or pass classes around either. if need be i can just maybe make the properties of each object i...

Help with DLL to Lib

I have converted a dll to lib. I gave it the lib and dll file and told it to remove the unnecessary stuff. I #included the .h file it created, and called GLU_DLLMAIN() in InitInstance just like I saw in the samples, but it still crahes on start up when it tries to initialize my static GLU object. What am I doing wrong? what is the proper...

Memory allocation to functions in C++

Hi All ! I am still a C++ newbie. Just came to read that the static member function of a class is not object specific - there is a single copy of the member functions for all the objects. Now two questions arise in my mind : What is the difference between an ordinary function and a static function "in terms of memory allocation only"...