static

final and private static

I read that doing: public final void foo() {} is equals to: private static void foo() {} both meaning that the method is not overridable! But I don't see the equivalence if a method is private it's automatically not accessible... ...

Static Global variable in Obj-C?

// in ClassA.h static NSString *globalStr = @"HelloWorld"; @interface ClassA ... @end // in ClassB.h #include "ClassA.h" // in ClassB.m ... NSLog(@"The global string: %@", globalStr); ... In C++, "static" should mean the variable or function has a internal linkage. But it is used to share the variable in this case, e...

Static and overriding in Java

public class B { static int i =1; public static int multiply(int a,int b) { return i; } public int multiply1(int a,int b) { return i; } public static void main(String args[]) { B b = new A(); System.out.println(b.multiply(5,2)); System.out.println(b.multipl...

When exactly is constructor of static local object called?

Possible Duplicate: What is the lifetime of a static variable in a C++ function? Say we have a code like this: Some class { Some() { // the ctor code } }; Some& globalFunction() { static Some gSome; return gSome; } When exactly 'the ctor code' is executed? As for normal static variables before main() or at the momen...

Alternatives to static variables in Android

I am using static Arrays and HashMaps to store some values in my AppWidgetProvider class. But they are becoming null when the process dies, so the widget does not work anymore. Are there any alternatives to using static members to store data for an AppWidgetProvider in Android? ...

CodeIgniter static class question

If I would like to have several static methods in my models so I can say User::get_registered_users() and have it do something like public static function get_registered_users() { $sql = "SELECT * FROM `users` WHERE `is_registered` = 0"; $this->db->query($sql); // etc... } Is it possible to access the $this->db object or c...

Odd C++ template behaviour with static member vars

This piece of code is supposed to calculate an approximation to e (i.e. the mathematical constant ~ 2.71828183) at compile-time, using the following approach; e1 = 2 / 1 e2 = (2 * 2 + 1) / (2 * 1) = 5 / 2 = 2.5 e3 = (3 * 5 + 1) / (3 * 2) = 16 / 6 ~ 2.67 e4 = (4 * 16 + 1) / (4 * 6) = 65 / 24 ~ 2.708 ... e(i) = (e(i-1).numer * i + 1) /...

template static classes across dynamic linked libraries

Hello, I have a templated class with a static value, like this: template <class TYPE> class A{ static TYPE value; }; in the code of a dll I assign the static value: code of DLL_1 A<float>::value = 2.0; I wish the value to be shared by all the dlls I'm using, i.e. I want that: code of DLL_2 printf("value on DLL_2 %f",A<flo...

Using a class as namespace

Are there any reasons I should not create a final class with static methods to avoid that some internal functions are called? final class ModuleGlobalFunctions { static public function generateWord { $result = ''; while (strlen($result) < 12) { $result = self::generateSyllable(); } return $result } static ...

C# static - What does the definition on MSDN mean?

Use the static modifier to declare a static member, which belongs to the type itself rather than to a specific object. ??? My encounter with this static keyword occurred when I defined a variable public int abc. When the value of this variable changed withing the brackets of while, or within the brackets of if, or within the ...

c++ static won't link

Can you help? The following code: class MT { public: static int ms_number; }; int MT::ms_number; yields: Error 8 error LNK2005: "public: static int MT::ms_number" (?ms_number@MT@@2HA) already defined in ProjName.obj Why? ...

Callbacks as part of a static member array.

Recently in a project I am working on, I needed to store callbacks in a static member array, like so: class Example { private static $_callbacks = array( 'foo'=>array('Example','do_foo'), 'bar'=>array('Example','do_bar') ); private static function do_foo() { } private static function do_bar() { } } To c...

When are global static const variables being initialized?

Hello all, I tried to search the site for this question but didn't find this exactly, although this subject is being discussed a lot... I have this declaration in a cpp file, not within any function: static const char* gText = "xxxxxxxxxxx"; Although it has a fixed size, I get a warning from a static analysis tool (Klocwork) when I'm...

(Embedded) C: void function() or #define FUNCTION()

Hi, im programming embedded devices and I was wondering what to use for a macrofunction, for example an init of some registers. should i make this static/const or define it as a macro? for example, this: #define FPGA_INIT()\ { \ /* Set function and direction of start_code pin*/\ P0SEL &= ~0x04; \ P0DIR |= 0x04; \ FPGA_START_CO...

Alternatives to static variables?

In my code I'm using static field for storing a particular value. public static int webServiceId; I have remove that and use any other solution. But the value should retain after postback. We can't use Session or ViewState here. Coz I'm working with services (in Service layer). Example: I get webservice id in the below method of xy...

PHP5.3 non-static variables in scope behaving static

Do PHP5.3 have any known bug issue that makes non static variables in scope behave Static ? I donno why in a if{}Scope I've { echo $_not_static; $_not_static = 5; } First Time it fires E_NOTICE as it should But second time it prints 5. I was Struggling with this for 3+ hours but not getting any hint of a fault from my side. ...

How to declare a static integer in h class in iphone?

I am not able to declare a static integer in h class in iphone. static int i; this gives an error "expected specifier-qualifier list before static". please help me out.How to resolve this.How can i declare a static variable globally in iphone.Thanks. ...

Template object as static member of the template class

Imagine the following template class (setter and getter for the member _t omitted): template<class T> class chain { public: static chain<T> NONE; chain() : _next(&NONE) {} ~chain() {} chain<T>& getNext() const { return *_next; } void setNext(chain<T>* next) { if(next && next != this) _next = next; ...

PHP: "Call to undefined method" error when calling static method from parent

How is the correct way to call a child class method from a parent class if both are static? When I use static classes it returns the error "Call to undefined method A::multi()", however when I use non-static methods there is no problem, for example: //-------------- STATIC ------------------ class A { public static function calc($a...

c++ static function unfound

I have this definition of the function in my class. The .hpp file: class SomeClass { public: static string DoStuff(string s); }; The .cpp file: #include "header.hpp" string SomeClass::DoStuff(string s) { // do something } Compiler says: **error C2039: 'DoStuff' : is not a member of 'SomeClass'** Can somebody help? EDIT: act...