Questions tagged [static]
Static is a term used in some programming languages to define a function or data storage area (field) that is not bound to any specific object instance. In the majority of cases this tag, if used, should be used in conjunction with a specific programming language tag.
static
16,469
questions
0
votes
0
answers
28
views
What happens when I have 2 static variables with the same name? [duplicate]
I am a Java beginner and am having trouble understanding the output of the System.out.println(((A)b).s) in the code.
My understanding is that static variables can be changed anywhere in the class and ...
1
vote
1
answer
47
views
Objective benefit of static local function that's only called once?
Recently I was looking at the source code of Stream.CopyToAsync, which is available here on github.
The author first validates the parameters and then calls a static local function that does the ...
0
votes
1
answer
32
views
CRTP static variable not initialized without constructor [duplicate]
I was trying to write a factory that types could register to using CRTP, like this question, and I was having some issues.
#include <iostream>
#include <map>
#include <functional>
...
0
votes
0
answers
22
views
Angular SSR generates browser and server folders on build. Can I use the site as static or with server-side rendering after configuration?
After setting up and running with SSR, Angular initially renders on the server.I'm on angular version 18.1.0
After the initial load, Angular takes over and the application operates as a Single Page ...
-3
votes
2
answers
64
views
Static variables in Visual Studio 2022 throws error [closed]
I am trying to declare a static variable in VS 2022 in a console app.
TreeNode prev = null;
static TreeNode treeToDoublyList(TreeNode root)
{
TreeNode dummy = new TreeNode(0, null, null);
prev ...
0
votes
1
answer
36
views
PHP: Lazy-evaluated static variable
I have a function that is called many times that look like this:
function attachImagesToProduct(Product $csProduct) {
$searchPath = realpath(__DIR__ . "/../images");
$files = scandir(...
-1
votes
0
answers
47
views
Can I generate a static variable with code? [duplicate]
I have a class that has a static dictionary that maps ids to names
class Foo {
static idToName = {
2: "John",
8: "Peter"
}
}
Now, I also need to be able to get the id ...
-2
votes
0
answers
13
views
Why constructor cannot access static variable inside the constructor block?
Why static variable can't be accessed using this keyword inside a constructor
I created a static variable and a no argument constructor inside a class when I try access the static variable with the ...
0
votes
1
answer
50
views
How to use `static` with an array of array in C
Given,
int last(int arr[3][6]) {
return arr[2][5];
}
I want to make it clear that arr can't be null with the static keyword.
The problem is that the following code won't work.
int last(int arr[...
0
votes
1
answer
55
views
Why I didnot get Multiple definition Error?
#include <stdio.h>
#define MAX 5
static int data = 10;
int increment(void *);
int increment(void *ptr)
{
int *p = ptr;
static int data =15;
for (int loop=0; loop < MAX; loop++...
-1
votes
0
answers
39
views
How to make a C++ struct that can have multiple independent static variables for each object of the struct? [duplicate]
I'm currently working on a Predator/Prey simulation in C++, and I'd like to keep track of certain stats (number born, number alive, and number died, specifically) for each one of various types (Animal,...
0
votes
0
answers
40
views
Accessing public assets via server action nextjs
I'm working on a Next.js 14 application where I need to use images stored in the public folder. While the images load correctly on the client side, I encounter issues when trying to read an image file ...
2
votes
1
answer
135
views
How to access a static property Swift 6 concurrency-safe?
My app uses a class A and its subclasses SubA_x.
A has a static property serialNumber that is only modified by class A when a subclass is initialized.
It sets a property let name so that every ...
0
votes
0
answers
49
views
Why /static/ not showing up for /admin in Django project?
So, I've been trying a bunch of things. Settings look good to me but maybe I am missing something.
I use: PostegreySQL, Reddis, Celery beat, nginx, gunicorn.
I can't figure out what the problem is: ...
0
votes
2
answers
68
views
Static variable and type: could there be another simpler way to implement a function that returns the same ID for each user-defined type?
I was working on creating an entity-component system on my own, and in doing this I have gotten help from a lot of YouTube videos, C++ references, recommended books, etc. While I was implementing a ...