static-variables Questions
4
Solved
Is there a use for flagging a variable as static, when it lies in the global scope of a .cpp file, not in a function?
Can you use the static keyword for functions as well? If yes, what is their us...
Descant asked 18/1, 2011 at 14:29
5
Solved
In C language, I want to access a global static variable outside the scope of the file. Let me know the best possible way to do it.
One of the methods is to assign an extern global variable the val...
Fao asked 29/12, 2009 at 6:9
4
Solved
Not sure I completely understand answers to similar questions that I found here, so trying to be absolutely sure:
I would like to have a local variable in a function, initialized only once (simila...
Sutton asked 22/2, 2018 at 8:47
6
Solved
If I have the following code:
class Foo(object):
bar = 1
def bah(self):
print(bar)
f = Foo()
f.bah()
It complains
NameError: global name 'bar' is not defined
How can I access class/static ...
Continent asked 1/4, 2009 at 21:23
1
I'm aware this question has been asked many times, but this seems to be a slightly different variation which I can't figure out.
Consider the following code:
#include <cstdio>
struct TestVal...
Erwinery asked 18/5, 2022 at 9:25
3
Why doesn't GCC (4.6.3) give me any warning for the unreachable code in the below example?
#include <stdio.h>
int status(void)
{
static int first_time = 1;
if (first_time) {
return 1;
f...
Majesty asked 22/6, 2013 at 10:54
5
I was wondering how to achieve the local static variable in java. I know Java wount support it. But what is the better way to achieve the same? I donot want the other methods in my class to access ...
Ain asked 13/6, 2014 at 3:5
3
Solved
In my .m file for a class named Ad , I have 3 static strings
static NSString *AdStateDisabled = @"disable";
static NSString *AdStateExpired = @"expired";
static NSString *AdStateActive = @"active"...
Ranite asked 19/10, 2010 at 4:31
6
Solved
What is the difference between a static and instance variable. The following sentence is what I cant get:
In certain cases, only one copy of a particular variable should be shared by all object...
Foreshore asked 18/1, 2014 at 13:12
3
Can you have a static variable in a static method? Would the value of this variable be preserved across all calls to the method?
eg.
public static void MyMethod()
{
static int x = 0;
x++;
}
Cozy asked 24/12, 2010 at 10:12
2
Solved
I am developing an application in C / Objective-C (No C++ please, I already have a solution there), and I came across an interesting use case.
Because clang does not support nested functions, my ...
Colucci asked 20/8, 2012 at 15:12
3
Solved
I have a function in R that I call multiple times. I want to keep track of the number of times that I've called it and use that to make decisions on what to do inside of the function. Here's what I...
Ostiole asked 6/7, 2009 at 18:48
1
Solved
My Question, see below, is how to declare STATIC functions and constants of a pre-ES6 class so they can be inherited?
A recap of the present ES6 class and pre-ES6 classes are given prior to the que...
Tamarin asked 22/5, 2021 at 10:33
6
Solved
Without any code in the subclasses, I'd like an abstract class to have a different copy of a static variable for each subclass. In C#
abstract class ClassA
{
static string theValue;
// just to ...
Arran asked 3/12, 2009 at 21:40
3
I have three files - global.php, test.php, test1.php
Global.php
$filename;
$filename = "test";
test.php
$filename = "myfile.jpg";
echo $filename;
test1.php
echo $filename;
I can read this ...
Camacho asked 3/9, 2013 at 9:42
5
Solved
In C# I have a generic class:
public class MyGeneric<ParameterClass> where ParameterClass: MyGenericParameterClass, new() {
public static int Variable;
}
Now in C++ if I instantiated a te...
Gemini asked 7/2, 2013 at 10:14
0
It's a fairly common idiom in the Win32 standard library to make the first member of structs be the size of the struct, like so:
#include <cstddef>
struct wrapped_float
{
std::size_t value...
Widener asked 18/7, 2019 at 22:33
1
I have a problem inside a pyspark udf function and I want to print the number of the row generating the problem.
I tried to count the rows using the equivalent of "static variable" in Python so th...
Salmonoid asked 18/1, 2019 at 11:4
1
Solved
Why does this static const int member variable appear to be accessible publicly in array definition?
I make the following declarations:
class Servo {
protected:
static const int maxServos = 16;
static Servo servos[maxServos]; //Array declaration
};
Servo Servo::servos[Servo::maxServos]; //A...
Sag asked 8/4, 2019 at 16:22
12
Solved
I have searched about static variables in C#, but I am still not getting what its use is. Also, if I try to declare the variable inside the method it will not give me the permission to do this. Why...
Superphysical asked 29/5, 2012 at 8:22
5
Solved
I want to have the same static variable with a different value depending on the type of class.
So I would have
public class Entity
{
public static Bitmap sprite;
public void draw(Canvas canvas...
Koch asked 19/9, 2009 at 7:55
2
Solved
Is a mutex defined statically in a function body able to lock properly? I am currently using this pattern in my logger system, but I have not tested it's thread safety yet.
void foo () {
static s...
Greenock asked 9/11, 2018 at 22:13
8
Solved
When I invoke the static variable y by using Checks.y (Checks being a subclass), the static block is not executed and the value of y doesn't get updated.
class Par {
static int y = 4;
}
cl...
Durga asked 4/11, 2018 at 8:25
4
Solved
This is a simplified version of what I want to accomplish:
In my script I want a variable that changes true and false everytime the script is executed.
<?php
static $bool = true;
// Print ...
Shirl asked 29/2, 2012 at 10:11
1
Solved
I declare a field in companion object, so it will be known in the functions in the companion object.
something like this:
class ProgramStructure {
companion object {
var index = 0
fun inc(){
...
Humanitarianism asked 21/5, 2018 at 20:11
1 Next >
© 2022 - 2024 — McMap. All rights reserved.