Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
1 answer
199 views

Having the scenario of a C++ library where a function does some calculations as it receives a container normally (not always) across multiples calls, and where the function needs to retain an ...
codev's user avatar
  • 43
2 votes
1 answer
84 views

I have a problem performing several scenarios one by one in unit testing. I'm testing a function, where static variables are used and they store states of variables after previous test scenarios. Is ...
PatrykL's user avatar
  • 21
7 votes
1 answer
579 views

I'm learning Rust and while doing research on static variables I came across this comment from 2018: Rust requires everything to be thread-safe (even if you're not using threads, the concept of a ...
Zebrafish's user avatar
  • 16.3k
-1 votes
1 answer
58 views

When declaring static thread_local variable, then each thread has a copy of that variable. Imagine a thread then spins another thread, will this variable still be a copy in the nested thread?
SpeakX's user avatar
  • 427
0 votes
0 answers
102 views

Considering the following example: A class named ObjectFactory is defined to manage the creation of several classes. These managed classes should be registered with the factory so that we can create ...
Woody Huang's user avatar
0 votes
1 answer
93 views

Inside a function, I have a static variable which is a struct, and only one of its fields are initialized: void func() { static constexpr xcb_change_window_attributes_value_list_t root_mask { ....
smac89's user avatar
  • 43.7k
-1 votes
1 answer
1k views

Assuming that we need to define a singleton with global read access with thread safety, the canonical method is to use OnceLock: /// A synchronization primitive which can be written to only once. /// /...
tribbloid's user avatar
  • 3,792
1 vote
0 answers
92 views

I am trying to create "plugin" factory. When an user requests creation of an object factory queries it's child factories and picks suitable one to create the object. Instances of child ...
KajzerSoze's user avatar
0 votes
2 answers
117 views

int e(int x, int n) { static int f=1, p=1; // f for factorial evaluation & p for power evaluation int r; if(n==0){ return 1; } else { r = e(x, n-1); p = p*x; f = f*n; ...
Deepak's user avatar
  • 11
1 vote
0 answers
79 views

I want to implement a self-register pattern in c++. My goal is to have one file defining a class and the class can self-register to a registry. My implmentation goes like this https://godbolt.org/z/...
Jiehong Jiang's user avatar
2 votes
1 answer
41 views

Python 3.10.6 Suppose you have the following files: main.py setter.py Folder/shared.py With these contents: # Folder/shared.py class Shared: i = 0 # something that is used in multiple locations #...
jagprog5's user avatar
  • 131
0 votes
2 answers
130 views

I have a function def compute_daily_quantities(): # compute some quantities, one of which is the variable, value After the first call to compute_daily_quantities, we need to add a constant, c to ...
h8n2's user avatar
  • 699
1 vote
1 answer
209 views

I wrote the below code to swap alternate elements in an array {eg. (1,2,3,4,5)-->(2,1,4,3,5) }. I wanted to try it using recursion. #include <iostream> using namespace std; void print(int *a,...
robinofautumn's user avatar
0 votes
0 answers
61 views

I am just learning templates in C++ and I came across the idea of using static variables in templates. I created a simple class containing a three dimensional vector. I decided to keep the 'unit caps'(...
Anubhav Jain's user avatar
2 votes
1 answer
547 views

Here is an example code why I started thinking about this void renderScene(void) { //Clear all pixels glClear(GL_COLOR_BUFFER_BIT); // Question : Declaring posAttrib as a static variable ...
busbug's user avatar
  • 75
0 votes
1 answer
45 views

Source The PHP doc says PHP implements the static and global modifier for variables in terms of references. <?php function test_global_ref() { global $obj; $new = new stdClass; $obj = ...
brittle_spirit's user avatar
0 votes
0 answers
48 views

I have the following testing program: // manager.h #pragma once #include <list> namespace testapp { class Manager { public: static Manager& instance(); void ...
ben yu's user avatar
  • 13
1 vote
2 answers
152 views

#include <iostream> class Test { public: static int numelem; Test() {} ~Test() {} int increment(); }; int Test::numelem = 0; int Test::increment() { return ++Test::numelem; }...
Heroking18's user avatar
0 votes
0 answers
40 views

I am studying this piece of code in the book "Design Patterns explained simply". It is the implementation of proytpe design pattern by the author Alexander Shvets. Although I thikn I have ...
pengfei_guo's user avatar
0 votes
0 answers
54 views

I was reading an article on references in CPP, where I found this example and couldn't understand how is that we are able to call a function and initialize a variable inside its call block. As the ...
Harsh Bhardwaj's user avatar
-1 votes
2 answers
127 views

There are class with multiple static variables, e.g. template<class T> struct A { // some code... static int i; static short s; static float f; ...
Sergey Troitskiy's user avatar
2 votes
3 answers
607 views

#include <pwd.h> #include <stdio.h> #include <stdlib.h> int main(void) { printf("%s %s\n", getpwnam("steve")->pw_name, getpwnam("root")->...
Steve Lau's user avatar
  • 1,101
1 vote
1 answer
447 views

On an embedded system (Cortex-M4) I write C++ that compiles with GCC arm-none-eabi-g++. Compiler version 10.2.1 20201103. My code is kind of complicated to copy paste it here, so here's an example: I ...
blinkbetter's user avatar
1 vote
0 answers
62 views

Say we have this class: public class Chicken { public static final Chicken THE_FIRST_ONE = new Chicken("Little"); public static final Chicken THE_FIRST_EGG_1 = new Egg("Humpty-...
Gunther Schadow's user avatar
2 votes
1 answer
4k views

I have a Blazor server app. Some variables on a specific razor page (main.razor) are defined as static because I want that these variables keep their values when the client navigates to other pages in ...
Mdarende's user avatar
  • 801

1
2 3 4 5
17