Questions tagged [static-variables]

In object oriented programming, a static variable is a variable which belongs to the class and not to object(instance) & a single copy to be shared by all instances of the class.

In object oriented programming, a static variable is a variable which belongs to a class rather than to a particular instance of the class.

799 questions
-2
votes
1 answer

How can i go to previous screen using static variable

I have problem implementing this since last 1 hour, I have more then 15 screen and slider menu as well in my code. What i am trying to achieve is when user swipe left a slider should open and when user swipes right he/she should able to go to…
-2
votes
2 answers

Why can I not initialize non-static member outside class declaration?

class ClassObject { public: ClassObject(); virtual ~ClassObject(); private: int x; }; int ClassObject::x=10; Why does it fail to compile? I think that if static members can be initialized this way, then it should also be possible for…
jiafu
  • 6,338
  • 12
  • 49
  • 73
-2
votes
1 answer

c Static float error: ‘????’ redeclared as different kind of symbol

unable to compile a c program, problem with symbol redefinition. Have tried various variable data type definitions, cannot understand what is going on here regarding float and static float. Have given it a good shot, any help appreciated. Chris $…
Glochief
  • 1
  • 1
-2
votes
2 answers

How can I define a variable inside a function to be called by an event

How can I set a function variable so can I call outside of the context, like this example function testSet(elmA,elmB) { elmA.onclick = function() { elmB.value = "ok"; …
Vitim.us
  • 20,746
  • 15
  • 92
  • 109
-3
votes
1 answer

How to keep track of last added element of Linked List using static pointer to Node?

class Node{ public: int info; Node* link; static int count; static Node* endNode; Node(){ this->info = 0; this->link = NULL; if(count==0) endNode = this; …
Karm0
  • 1
  • 1
-3
votes
1 answer

How to make a static local variable in golang

/* Description: Write a function canSum(targetSum, numbers) that takes in a targetSum and an array of numbers as arguments. The function should return a boolean indicating whether or not it is possible to generate the targetSum using numbers from…
-3
votes
1 answer

unable to access the static variable

#include class test { int a, b; public: static float f; }; float test::f; int main() { test::f = 3.14; std::cout << f; } "unable to access the static variable" even though I am using the class label.
ravi
  • 1
-3
votes
1 answer

Undefined Reference to deck::array1 in c++

I have header file in which I have static function which are public and i have a private static array. In my c++ file file i am calling my array from one of this static function and getting error "UNDEFINED REFERENCE TO abc::ARRAY". why I am getting…
Viral
  • 47
  • 8
-3
votes
2 answers

static const variable as macro

I'm programming in C++ and want to use static const variables instead of macros for magic values. In the example: static const int myx = 10; int incbyx(int y){ return y + myx; } The assembly generated directly uses the value 10: 103ec8:…
josecm
  • 413
  • 3
  • 15
-3
votes
6 answers

why static variable initialised in each calling of function but we have to declare it every time in C

I read that : static variable is initialised only once (unlike auto variable) and further definition of static variable would be bypassed during runtime. from the link. then why I am getting error that "i was not declare " in the code given…
-3
votes
3 answers

C++ independent static variable for each object inside a method

Consider the following code: #include class CTest { public: CTest() : c(0) {} void Method1() { c++; std::cout<<"c: "<
ar2015
  • 5,558
  • 8
  • 53
  • 110
-3
votes
1 answer

static variables, creating new variables from classes in a static method inside my public class

ok this code was working earlier, but all of a sudden, java tells me that i can't reference the two stop objects (origin and destination) i'm trying to create in the loop from a static context, but i'm not referencing them, i'm creating a new…
-4
votes
2 answers

Access static variable from a different class

So I have two classes: A Main class with the public static void main(String args[]) method and a Voice class that accesses a static variable from that class. Within the main class are methods that are used by itself, and are required to be static…
-4
votes
3 answers

explaining the behavior of this "static variable" in C

I'm reading "hacking, The Art of Exploitation" book, and this code sample really confuses me. It's within the context of Global Variable Scope: #include void function() { // An example function, with its own context int var = 5; …
Soask
  • 691
  • 12
  • 21
-5
votes
4 answers

When is it better to use static variable?

I am wondering why sometimes I see code with static variable? When is it better to use static variable instead of "normal" variable? If its value do not change from an istance to another, is it not better to use final variable?
Liz Lamperouge
  • 681
  • 14
  • 38
1 2 3
53
54