Following this question Having a static string constexpr gives a linker error
In this question this code could not compile:
#include <iostream> struct Test { static constexpr char text[] = "Text"; }; int main() { std::cout << Test::text << std::endl; // error: undefined reference to `Test::text' }
From the comment, this code can compile:
#include <iostream> struct Test { static constexpr auto text = "Text"; }; int main() { std::cout << Test::text << std::endl; }
My question is: why does the auto version work, but the char version array does not work?
Could you point out the statement in the standard that allows the second version and prohibits the first?
I looked at the weird behavior with the constexpr constant variable , but it seems to be another question.
source share