vendredi 4 août 2017

Cannot declare static constexpr char []

I've read all the answers related with this issue but honestly I'm not sure if I've fully understand the solution. I'm using C++11.

Lets say I really would like to declare something like static constexpr char value[] = "foo".

If I use NetBeans/TDM_MINGW I get an error which I suppose is a link error reporting undefined reference to "variable_name".

Trying the same code in MS VS 2015 I get "expression did not evaluate to a constant".

A simple static constexpr char * solves the problem but I lost the ability of using expressions like sizeof.

Simple and straightforward questions (if possible straightforward anwsers) :

  1. Is there a way to declare a static constexpr char [] inside struct/class?
  2. If 1) is false is there a cleanest solution to overcome this? static constexpr char *????
  3. Or the old static const char [] is still the best approach for this case?
  4. I've tested a solution that works but far from being "clean" static constexpr array<char,50> getConstExpr(){ return array<char,50> {"Hell"} }. It works fine but I have to declare the size of the char array :(

Aucun commentaire:

Enregistrer un commentaire