Linked Questions

17 votes
2 answers
3k views

In C++11 and C++14, why do I need constexpr in the following snippet: class Foo { static constexpr double X = 0.75; }; whereas this one produces a compiler error: class Foo { static const ...
Stefano Sanfilippo'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
12 votes
1 answer
7k views

==> See the full snippet code and compilation on coliru. I have a LiteralType class filling constexpr requirements: struct MyString { constexpr MyString(char const* p, int s) : ptr(p), sz(s) {} ...
oHo's user avatar
  • 55.1k
4 votes
2 answers
2k views

This work: template<typename T> struct Something { static constexpr const char* str = "int"; }; int main() { std::cout << Something<int>::str << std::endl; } But it doesn't: ...
ABu's user avatar
  • 12.5k
4 votes
2 answers
3k views

I am looking for a portable one line replacement for the #define in the following code. The replacement should hide the word APPLE in the namespace of the Foo object. class Foo { public: #define ...
Mark Lakata's user avatar
  • 21.1k
2 votes
2 answers
3k views

The following code produces an undefined reference to 'Test::color'. #include <iostream> struct Color{ int r,g,b; }; void printColor(Color color) { //printing color } class Test { ...
user3738870's user avatar
  • 1,650
1 vote
1 answer
2k views

If I want to use some convenience stuff like make_array I have no chance to declare my array first and later make the definition as done in "earlier" times because the type of my var is not available ...
Klaus's user avatar
  • 26k
3 votes
3 answers
1k views

Here's the minimum code: #include <iostream> #include <complex> using namespace std; class Test { static const double dt = 0.1; public: void func(); }; void Test::func() { ...
eimrek's user avatar
  • 225
2 votes
3 answers
2k views

below is my code: // types.h template <typename T> struct type_to_char {}; template <> struct type_to_char<char> { static constexpr char str[] = "baz"; }; // main.cpp #include &...
Jytug's user avatar
  • 1,126
2 votes
1 answer
580 views

I'm working on a kernel and I want to make my static data member constexpr so I can have its values in an enum class. However, if I do so I get an undefined reference error. It only seems to work if I ...
user4038984's user avatar
5 votes
2 answers
329 views

This is my code, a.cpp struct int2 { int x, y; }; struct Foo{ static constexpr int bar1 = 1; static constexpr int2 bar2 = {1, 2}; }; int foo1(){ return Foo::bar1; // this is ok for ...
xdot's user avatar
  • 148
3 votes
0 answers
1k views

I'm trying to use a class to group all the parameters of a template data structure, in particular an intrusive AVL tree. The user would do something like this: struct MyEntry { MyEntry *parent; ...
Ambroz Bizjak's user avatar
3 votes
1 answer
691 views

I got this compile time string comparison from another thread using constexpr and C++11 (http://stackoverflow.com/questions/5721813/compile-time-assert-for-string-equality). It works with constant ...
Negative Zero's user avatar
6 votes
1 answer
410 views

Consider the following code: #include <iostream> template<class T> struct foo {}; template<> struct foo<int> { static constexpr char value[] = "abcde"; }; ...
llllllllll's user avatar
  • 16.5k
1 vote
1 answer
504 views

Compiling with -std=c++14 the following code: #include <memory> class A { public: static constexpr int c = 0; std::shared_ptr<int> b; A() { b = std::make_shared&...
Nicola Lissandrini's user avatar

15 30 50 per page