Questions regarding initialization code of static members
Questions tagged [static-initialization]
325 questions
1
vote
1 answer
how to replace static elements initialization for Command pattern?
I want to replace if else statements:
if (userSalutation.equalsIgnoreCase("mr")) {
screenPage.selectMr();
} else {
screenPage.selectMs();
}
selectMr() performs just click on this buttons.
With Command pattern…

catch23
- 17,519
- 42
- 144
- 217
1
vote
2 answers
Fortran derived type in common: initialization?
I got troubles with this common:
COMMON /REDCOM/ DPREC,NITMA,INDIC,NBERR,NCAR,KMOTLU,
& REDVAR,MOCDER(2)
COMMON /REDCO1/ CTEXT
C
type(double_st) :: DPREC
INTEGER ::…

janou195
- 1,175
- 2
- 10
- 25
1
vote
1 answer
Factory class implementation problems
I implemented a factory class based on the following article available here.
I have one problem, however, and I think it’s related to compiler optimisations.
I have a hierarchy of classes where class Node (in Node.h/Node.cpp) is the base class and,…

zync
- 463
- 3
- 17
1
vote
1 answer
Static Initializer/Constructor Ordering
I ran into an interesting bug today, the code below would crash on the commented line on some machines, and not others. The problem appears to be related to ordering of static constructors, vs static initializers, and inheritance.
The fix was to…

innominate227
- 11,109
- 1
- 17
- 20
1
vote
2 answers
Invoke java class static initialization via VM option
Is there any way to force static initialization of some class B before entering the main() method of class A, without changing class A, using only VM options?

FireFry
- 125
- 6
1
vote
5 answers
Static Initialization
I'm running into a problem when I compile my code. When I compile my code foo2.var returns null in class foo and I can't seem to figure out why. Is there something wrong in how I'm doing the static initialization in the foo2 class to cause…

MacAttack
- 25
- 6
1
vote
3 answers
Is it standard / recommended practice to covert checked to unchecked exceptions in static blocks?
A static block cannot throw checked exceptions but I have seen a couple of codes where checked exceptions are converted unchecked and thrown from static blocks. An example of such would be reading a text file of dictionary. We do not want to read…

JavaDeveloper
- 5,320
- 16
- 79
- 132
1
vote
0 answers
Why is the compiler not generating code for my uninstantiated template class's static member variable?
This question is hard to word, primarily because of the terms class instantiation vs. template instantiation. I have a template class that is full of static functions and members. Each specialization of this template needs to have some…

Collin Dauphinee
- 13,664
- 1
- 40
- 71
1
vote
1 answer
Easiest way to locate a static variable in code?
I have a bug on my plate to locate and rewrite a static variable in one of our libraries that is taking up launch time in our application. I am not familiar with the library code base and am asking for good heuristics/techniques/grep commands/etc.…

fbrereto
- 35,429
- 19
- 126
- 178
1
vote
1 answer
what is the context of a static initializator, and how do I declare a friendship to it?
class test{
static const int veryprivate=3;
};
const int anarray[]={test::veryprivate};
g++ smartly points out that anarray is neither a function or a member function. Is it possible to fix this code keeping veryprivate private? C++11…

Lorenzo Pistone
- 5,028
- 3
- 34
- 65
1
vote
2 answers
Does the C++ static initialization fiasco apply to class hierarchy?
I'm getting a crash (debug assertion failure: invalid CRT heap pointer in VC++ 2008) in static initialization, and I'm not sure I understand why.
I've read all about the static initialization fiasco over at the C++ FAQ, and I thought I had a grasp…

Brian A. Henning
- 1,374
- 9
- 24
1
vote
1 answer
Why does c++ class need to define static field(data member) outside the class scope?
Possible Duplicate:
Initializing private static members
Why I can't initialize non-const static member or static array in class?
It is strange to me. Why not assume there is a static field at the global scope?

Jichao
- 40,341
- 47
- 125
- 198
1
vote
2 answers
static struct in anonymous namespace
that this snippet of code actually do?
#include
#include
#include
using namespace std;
void test();
namespace {
static struct StaticStruct {
StaticStruct() {
test();
}
}…

JohnTortugo
- 6,356
- 7
- 36
- 69
0
votes
2 answers
A better way to initialize a static array member of a class in C++ ( const would be preferred though )
I have a static array of pointers to functions as a member of a class.
I need to initialize it, but it turns out this array is 64K items long, so it's impractical to initialize it with a static initializer like { x, y, z, ... } as it would clutter…

Petruza
- 11,744
- 25
- 84
- 136
0
votes
1 answer
Initialization of static thread_local member inside lambda that does not use that member
I have code that is similar to the following (this code does not compile, is just for illustration purposes):
class A {
std::mutex m_;
std::vector bv_;
struct B {
B() {
std::lock_guard _(m);
bv_.push_back(this);
…

user2296145
- 276
- 2
- 8