Linked Questions

309 votes
3 answers
199k views

If I have a variable inside a function (say, a large array), does it make sense to declare it both static and constexpr? constexpr guarantees that the array is created at compile time, so would the ...
David Stone's user avatar
  • 29.4k
19 votes
3 answers
2k views

Given the following code: struct A { static constexpr int a[3] = {1,2,3}; }; int main () { int a = A::a[0]; int b [A::a[1]]; } is A::a necessarily odr-used in int a = A::a[0]? Note: This ...
Lightness Races in Orbit's user avatar
8 votes
4 answers
2k views

I am a bit confused by the static in-class initialization of a const member. For example, in the code below: #include <iostream> struct Foo { const static int n = 42; }; // const int Foo::...
vsoftco's user avatar
  • 56.9k
9 votes
3 answers
7k views

When I try to use a static const to initialize a unique_ptr, I get an "undefined reference" error. However, when I new a pointer using the same constant, the symbol seems to be magically defined. ...
eswens13's user avatar
  • 163
8 votes
2 answers
2k views

I know there are a lot of similar questions, but somehow different questions. It is about the following situation: #include <iostream> #include <array> template<typename T> class ...
marlam's user avatar
  • 600
5 votes
1 answer
4k views

This is what I've got: struct Foo { static std::array<double, 4> acgt_default_background_frequencies() { return {0.281774, 0.222020, 0.228876, 0.267330}; } }; But I'd prefer to not use a ...
JDiMatteo's user avatar
  • 13.4k
17 votes
1 answer
517 views

I was surprised to find that GCC and Clang disagree on whether to give me a linker error when passing a static constexpr member by value when there is no out-of-class definition: #include <...
Joseph Garvin's user avatar
7 votes
1 answer
776 views

I am getting the error in while linking my object files: #include <cstdint> #include <array> enum SystemType : uint8_t { AC, DC, HCP, EFF }; template<SystemType TYPE> struct ...
apramc's user avatar
  • 1,386
0 votes
1 answer
83 views

The code below triggers error with gcc 'undefined reference Foo::d' and 'undefined reference Foo::i'. Strangely, it happens only if I compile it in -Og, or -O1 optimization mode, but not with -O2 or -...
one_two_three's user avatar
2 votes
1 answer
125 views

In this answer in SO the OP says: Per basic.def.odr/2, the set of potential results of A::a[0] is empty, so A::a is odr-used by this expression. Doesn't A::a[0] satisfy the second bullet point in [...
João Afonso's user avatar
  • 1,934
1 vote
0 answers
56 views

I have the following simple struct, which represents an OpenGL texture: #pragma once #include <GL/glew.h> #include <string> #include "Shader.hpp" struct Texture { static constexpr ...
user3487347's user avatar