c++ - const constexpr char* vs. constexpr char* -


i know difference between const , constexpr. 1 compile time constant , other either compile time or runtime constant.

however, array of chars/strings, i'm confused why compiler complains 1 being used on other.

for example have:

constexpr char* a[2] = {"....", "....."};  const constexpr char* b[2] = {"....", "....."}; 

with declaration "a" get:

iso c++ forbids converting string constant 'char*' [-wwrite-strings] 

but declaration "b" no warnings.

why const qualifier rid of warning? aren't both of them "const char*" anyway? ask because both declared constexpr should make const char* default?

i'd expect fine :s

const tells compiler chars pointing should not written to.

constexpr tells compiler pointers storing in arrays can totally evaluated @ compile time. however, doesn't whether chars pointers pointing might change.

by way, way write code be:

const char * const b[2]; 

the first const applies chars, , second const applied array , pointers contains.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -