Is there a reason why a fully initialized constexpr member have to be defined again outside the class declaration ?
Isn't it redundant since it's static, constant and already fully initialized inside the declaration ?
Here is an example. I am using C++17
#include <iostream>
struct Settings {
static constexpr const char * str[2] = {"Hello 1", "Hello 2"};
};
void print(int i) {
printf("%s\n", Settings::str[0]); // Does not need a definition
printf("%s\n", Settings::str[i]); // Needs a definition
}
int main() {
print(1);
return 0;
}
The line :
printf("%s\n", Settings::str[i]);
generate this error :
undefined reference to `Settings::str'
But not the line :
printf("%s\n", Settings::str[0]);
Thanks