It is more of the rhetorial question (and a rant). Pre-11 everytime I had to make a library which exhibited static const char* const (as in static const char* const class_name = "ClassA";
) as class members, I knew the library could no longer be header-only - I had to provide a .cpp file with a definition of this variable and it's value.
So instead, I had to turn it into the static function name()
, returning the pointer.
Than C++11 came, and now I can have static constexpr char[]
as my meber - and I can even give it a value in my header! But I still have to provide the definition... so I am not excited at all.
Why would that be the case? If constexpr can be evaluated by compiler at compile time, why do I need a definition of it? Why does it have to have linkage at all?
Aucun commentaire:
Enregistrer un commentaire