Linked Questions

3 votes
2 answers
3k views

#include <iostream> using namespace std; template<typename T> void print(T&& mX) { std::cout << std::forward<T>(mX) << std::endl; } struct SomeStruct { ...
Vittorio Romeo's user avatar
2 votes
1 answer
2k views

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 { ...
user2010633's user avatar
2 votes
2 answers
748 views

#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]; } }; ...
a_girl's user avatar
  • 1,245
2 votes
2 answers
562 views

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 ...
Oersted's user avatar
  • 3,804
1 vote
0 answers
231 views

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 { ...
Irbis's user avatar
  • 1,581
1 vote
0 answers
207 views

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&...
wiRe's user avatar
  • 101
1 vote
0 answers
177 views

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<...
Moia's user avatar
  • 2,394
0 votes
0 answers
104 views

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, ...
spfrnd's user avatar
  • 946
0 votes
0 answers
58 views

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: ...
Ondrej's user avatar
  • 1,027
0 votes
0 answers
54 views

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 ...
S3gfault's user avatar
  • 393
1 vote
0 answers
28 views

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[...
Quest's user avatar
  • 2,853
29 votes
5 answers
5k views

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 ...
shauryachats's user avatar
  • 10.5k
18 votes
2 answers
15k views

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 ...
monkey0506's user avatar
  • 2,627
13 votes
2 answers
1k views

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++...
eg0x20's user avatar
  • 259
20 votes
4 answers
2k views

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 ...
Ujjwal Aryan's user avatar
  • 4,147

15 30 50 per page