Skip to main content

Questions tagged [static-members]

A static member in C++ is a either a static data member or a static member function. It is shared by all, and independent of any instances of a class.

2 votes
2 answers
125 views

How to use the correct instance with static inline member pointer and static member function?

I have a static callback member function that calls a non-static window procedure member function via a static inline pointer. The problem is, it ends up calling the last instance. Here is an example ...
machine_1's user avatar
  • 4,444
0 votes
0 answers
35 views

python class variable not updated when passed to new Process [duplicate]

Why doesn't a new Process get the updated class attr value (in Windows btw). (It's the same if the attr was just a str). I'm guessing the 3rd case worked because assignment gave it a instance attr. ...
TurtleTread's user avatar
  • 1,308
0 votes
0 answers
82 views

Static member initialization and specialization in template classes: differences between const and constexpr

Experimentally, I know how to declare/initialize/define static data member of various kinds (mainly by reading the compiler diagnosis) yet I realize that I don't really understand the rules behind ...
Oersted's user avatar
  • 1,643
0 votes
0 answers
67 views

In-class vs out-of-class static member initialization: const(expr)ness and ODR

Experimentally, I know how to declare/initialize/define static data member of various kinds (mainly by reading the compiler diagnosis) yet I realize that I don't really understand the rules behind ...
Oersted's user avatar
  • 1,643
1 vote
0 answers
54 views

explicit instantiation of static var in class template [duplicate]

I have the following class with a static data member but linking failed with undefined reference to X<int, int>::list #include <vector> template < typename T1, typename T2 > class X ...
Klaus's user avatar
  • 25.3k
0 votes
2 answers
187 views

Is a static member function visible inside a templated class before it is declared?

Should static member function b be visible to the requires-clause of the default constructor of s? What does the C++20 standard say about the legality of the provided example? template<auto...> ...
303's user avatar
  • 4,170
6 votes
1 answer
209 views

Is the initialization order of global variables and static inline data members relative to each other guaranteed?

The code below is in the same translation unit and A::v is defined after x, why A::v is not initialized to "ok" ? #include <string> #include <iostream> std::string foo() { ...
konchy's user avatar
  • 824
3 votes
1 answer
105 views

Can't use constexpr function of nested class [duplicate]

struct Foo { struct Bar { int data = 0; //constexpr Bar() = default; // Doesn't work either constexpr Bar() : data(0) {} }; static constexpr Bar bar = {}; // ...
Newline's user avatar
  • 837
3 votes
3 answers
214 views

Why can a "const static int" member be initialized within a class, but not a "const static other" member?

Look at the code below, this const static int num1 = 8; compiles. However, the const static double num2 = 8.8; code gives an error. Their modifiers are all const static, so why does int work, but ...
SleepingCat's user avatar
0 votes
0 answers
36 views

How to make Java class to initialize another class, and execute static java code block conditionally

I am using WireMock and managed to configure it to use SSL in JUnit 4 tests and disable throwing error if the hostname doesn't match the WireMock self signed certificate with CN=Tom Akehurst. The code ...
tarekahf's user avatar
  • 908
0 votes
2 answers
52 views

Getting an error of "Reference to non-static member function must be called"

I'm not able to understand what this error means, and what is causing it. Here is my code, please help me to point out the mistake: class Solution { public: bool sortbysec(const pair<int,int>...
Krishna Gaggar's user avatar
-2 votes
2 answers
420 views

Inner classes can have the static members inside it in java 17? [duplicate]

I was reading the articles regarding the inner classes and out of curiosity I declared the static members within the inner class. Strangely no compile time error was shown and the code just executed ...
Rishi Bharadwaj's user avatar
-1 votes
1 answer
82 views

Seeking clarity regards C++ static member initialization

I am quite confused regarding intialization and usage of C++ class/struct static members. Let's say, that I have defined a struct MapMetaData in a header file named Constants.h. Here's how it looks - ...
skpro19's user avatar
  • 519
3 votes
1 answer
174 views

How do I initialize a static random generator data member?

I have Random class, and I don`t know how correctly initialize its static data members. // random.h #pragma once #include <random> class Random { private: static std::...
Ростислав Романець's user avatar
0 votes
1 answer
174 views

Where in C++17 document say that class static member function has external linkage?

I've seen some statements that static member function has external linkage. However, I cannot find the statement from C++17 official document. Does anyone know? If anyone provides the line from c++17 ...
YoonSeok OH's user avatar

15 30 50 per page
1
2 3 4 5
80