Linked Questions
40 questions linked to/from Undefined reference to static constexpr char[]
3 votes
2 answers
3k views
Linker error (undefined reference) with `static constexpr const char*` and perfect-forwarding [duplicate]
#include <iostream> using namespace std; template<typename T> void print(T&& mX) { std::cout << std::forward<T>(mX) << std::endl; } struct SomeStruct { ...
2 votes
1 answer
2k views
Undefined reference to static constexpr char[][] [duplicate]
I tried to init char[][] static public field in class but in another function this field is undefined. How I use consexpr or exists another method to init static (dictionary) array? class A { ...
2 votes
2 answers
748 views
c++ linker error and undefined reference when accessing static constexpr member [duplicate]
#include <stddef.h> #include <array> struct S { static constexpr std::array<int,5> sca = {1,2,3,4,5}; static constexpr int foo(size_t i) { return sca[i]; } }; ...
2 votes
2 answers
562 views
undefined symbol when initializing a static constexpr home-made string variable with gcc in debug configuration, C++14 [duplicate]
I'm failing to understand a linker error in C++14 with gcc. My purpose was to have a template that exposes a name, according to a non-type template parameter (a kind of compile-time mapping between a ...
1 vote
0 answers
231 views
How to declare constexpr c-string member? [duplicate]
How to declare constexpr c-string member ? Non-member constexpr c-string can be declared this way: constexpr char id_[] = "aaa"; so I have though that I can declare it this way: struct T { ...
1 vote
0 answers
207 views
Undefined reference to static constexpr, if passed as function parameter pack with O0 (works with higher optimization levels) [duplicate]
The following code snippet can only be linked if optimization level was higher than O0: #include <cstdio> #include <utility> void vf(std::size_t n, ...) {printf("%zu\n&...
1 vote
0 answers
177 views
Undefined reference to class when using std::cout [duplicate]
Consider this code: rgb.h namespace Company{ namespace Core{ constexpr int RGB_MIN = 0; constexpr int RGB_MAX = 255; template<typename T> class RGB; using RGBi = RGB<int>; template<...
0 votes
0 answers
104 views
Linker errors with constexpr arrays [duplicate]
I have been writing code that uses constexpr float[n] to hold coefficients of a polynomial fit. The code boils down to the following snippet: #include <iostream> template<typename Real, ...
0 votes
0 answers
58 views
Initialization of static members in header files in C++ [duplicate]
I have a question related to the initialization of static members in the header files. In the following example: some_project.h class MyClass { private: void foo() const; private: ...
0 votes
0 answers
54 views
How to have a static constexpr array in a struct [duplicate]
So I want to have a struct like this: struct A { static constexpr int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; }; In which I have a static constexpr array. If I try to access this ...
1 vote
0 answers
28 views
GCC fails to link static constexpr member variable under C++14 [duplicate]
The following code compiles with c++17 but fails with c++14 undefined reference to `Class<...>::name' template<char... n> class Class { public: static constexpr const char name[...
29 votes
5 answers
5k views
Why static variable needs to be explicitly defined?
In the class: class foo { public: static int bar; //declaration of static data member }; int foo::bar = 0; //definition of data member We have to explicitly define the static variable, otherwise ...
18 votes
2 answers
15k views
Proper initialization of static constexpr array in class template?
Static class members in C++ have caused a little confusion for me due to the standard's verbiage: 9.4.2 Static data members [class.static.data] The declaration of a static data member in its class ...
13 votes
2 answers
1k views
Why type const double is not captured by lambda from reaching-scope, but const int is?
I seem can't understand why the following code with type const int compiles: int main() { using T = int; const T x = 1; auto lam = [] (T p) { return x+p; }; } $ clang++ -c lambda1.cpp -std=c++...
20 votes
4 answers
2k views
What is the difference between declaration and definition of a variable in C++? [duplicate]
My question stems from studying Effective C++ by Scott Meyers. In Item II of that book, following is written : To limit the scope of a constant to a class, you must make it a member and, to ensure ...