Static constexpr char m_pszFoo [] = "*** FOO ***" has a compilation error expression that did not evaluate the constant

error code C2131.

intelisense does not complain even when I call the size of this variable in other files that intelisense knows the size. What am I missing to get this to work? Any help is appreciated. In fig. See below Intelisense non-complaining and sizing.

enter image description here

Ah example:

class a { private: static constexpr char m_pszFoo[] = "***FOO***"; // compile error on this line C2131 expression did not evaluate to a constant public: a() { sizeof(m_pszFoo); }; // no compile error here }; 

to reproduce all you have to do is include ah in any other file. It will not play without power on.

+5
source share
1 answer

So, I came up with a work around b \ c that the error message showed that I need to add a constant somewhere

 static constexpr char const m_pszFoo[] = "**FOO***"; 

for some reason, if we tell the compiler that we cannot change the char that the line points to msvc.

* Change *

I came up with some tips to report a bug using microsoft and allow them to investigate, since it looks like an interop error with msvc. here's the link connect.microsoft: https://connect.microsoft.com/VisualStudio/feedback/details/2781048

+4
source

All Articles